windows batch improvement (was: Could not open input file. drush.php)

picardo - June 30, 2009 - 17:22
Project:Drush
Version:All-Versions-HEAD
Component:Code
Category:bug report
Priority:normal
Assigned:Owen Barton
Status:needs review
Issue tags:commandline, Windows
Description

This is an error I am encoutnering on my WIndows Vista machine. I have put the drush directory in the path, and when I try drush.bat, this error comes up. But it also happens when I use the file location + drush.bat. Oddly enough, when I run drush.bat from its own directory, it seems to work fine. It doesn't work when I call it from any other directory.

#1

saariant - July 27, 2009 - 08:49

I am getting the same error.

#2

saariant - July 27, 2009 - 09:13

solution found here:

http://drupal.org/node/330023

you need to define the hole path to the drush.php file inside the drush.bat file

#3

hass - August 5, 2009 - 22:30
Status:active» needs review

Change the drush.bat to:

@php.exe %0\..\drush.php %1 %2 %3 %4 %5 %6 %7 %8 %9

#4

moshe weitzman - August 11, 2009 - 02:09
Assigned to:Anonymous» Owen Barton

#5

Durrok - August 21, 2009 - 09:35

Point it to the where drush.php is at. Ex: Mine is located at C:\drush\drush.php so my drush.bat looks like:

@php.exe C:\drush\drush.php %1 %2 %3 %4 %5 %6 %7 %8 %9

#6

hass - August 21, 2009 - 10:44

Use #3 only!

#7

Durrok - August 21, 2009 - 17:36

hass - Tried it and it does not work in windows xp. Same error.

I know mine works however. :) Any reason not to do that?

#8

rsvelko - August 28, 2009 - 19:23

To sum it up: we have 2 fixes - one for Vista and 1 for XP - the bat file should be patched? How?

Do we need to patch the docs/README?

#9

hass - August 28, 2009 - 21:41

Use #3 only! It works on all Windows Versions the same way!

@Durrok: I have developed it on WinXP. It must works on all NT versions. Your version is static and will not work in a general way.

#10

legion80 - September 4, 2009 - 21:27

for me what I did was change the .bat to read:

@php.exe "%~dp0drush.php" %1 %2 %3 %4 %5 %6 %7 %8 %9

(don't forget the quotes).

In DOS batch scripting %~dp0 represents the directory of the batch file.

As long as your php.exe and drush.bat paths are in PATH (which I changed by going to My Computer > Properties > Advanced (tab) > Environment Variables (button), and adding the "PATH" variable (without quotes) set to ";;%PATH%" (without quotes)) this should allow you to run drush from any directory.

#11

hass - September 5, 2009 - 07:53

I tried this clean variant too, but haven't worked...

#12

wingflap - September 6, 2009 - 05:42

I'm running Vista, Uniform Server 3.5, and the current Drush. I've installed Drush in D:\server\drush. Php is located in d:\server\wdrive\usr\local\php.

The php.ini includes a bunch of libraries referenced by: extension = [libraryname].dll for each of the libraries. I set my path to include the drush folder and the php folder as above.

In drush.bat, I changed drush.php to:
@php.exe "%~dp0drush.php" %1 %2 %3 %4 %5 %6 %7 %8 %9
(thanks leigion80 - been a long time since i've been that deep in dos scripting. nice addition.)

When I execute 'drush' (with or without a parameter) from any location (other than the php folder), I see warnings about the inability to load a php extensions library. Then I see the drush help followed by an error saying that drush.php [parameter-if supplied] can't be found:

D:\server\wdrive\usr\local>drush
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/PHP/extens
ions\php_gd2.dll' - The specified module could not be found.
in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/PHP/extens
ions\php_mbstring.dll' - The specified module could not be found.
in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/PHP/extens
ions\php_mysql.dll' - The specified module could not be found.
in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/PHP/extens
ions\php_mysqli.dll' - The specified module could not be found.
in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/PHP/extens
ions\php_pdo.dll' - The specified module could not be found.
in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/PHP/extens
ions\php_sockets.dll' - The specified module could not be found.
in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/PHP/extens
ions\php_sqlite.dll' - The specified module could not be found.
in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/PHP/extens
ions\eaccelerator.dll' - The specified module could not be found.
in Unknown on line 0

This is followed by:

Execute a drush command. Run `drush help [command]` to view command-specific help.

if no parameter is provided or:

Could not open input file: d:\server\drush\drush.php status

if a parameter (like status) is provided.

When I run within the php folder, I don't get the library errors, but I still get the same drush errors. Sounds like I have 2 problems. I want to be able to call drush from any folder (like a /sites/all/modules folder) and still have php load properly. And second, the file not found error.

Anyone else using Uniform Server? Are you having similar problems? I've been beating my head over this but I'm drooling from what I'm seing this thing being capable of. I'd really like to get this working in an XP/Vista environment.

#13

wingflap - September 7, 2009 - 06:39

Found a typo in my Path statement.

I've gotten rid of the drush.php not found. When I'm not in a site folder, I see the usual library load errors followed by:

Could not find a valid Drupal installation
(which is good)

When I run it in a folder with a site, I get html spit out at me which basically translates to this:

The site is currently not available due to technical problems. Please try again later. Thank you for your understanding.
If you are the maintainer of this site, please check your database settings in the settings.php file and ensure that your hosting provider's database
server is running. For more help, see the handbook, or contact your hosting provider.

The mysqli error was:
Unable to use the MySQLi database because the MySQLi extension for PHP is not installed. Check your <code>php.ini</code> to see how you can enable it..

So for me, it appears that drush is functioning with the exception of loading php correctly (which I would consider a limitation ;) ). How do I invoke php from the batch file run from within a website folder so that the integrity of php's ini file and the relative locations of the extensions (libraries) are maintained? If I figure this out, I'll be drushing away!

---UPDATE---
Great explanation of running php CLI in the Uniform Server Wiki:
http://wiki.uniformserver.com/index.php/PHP_CLI:_PHP_INI

You can create a separate php ini file for your command line PHP execution that's separate from php invoked by the server. Hope this is helpful to someone. The suggestions above put me on the right track.

#14

Durrok - September 15, 2009 - 20:08

@hass ... your version does not work though? If you change the path in mine (as I advise to do) that will work on any PC.

I have tried yours on three different machines with drush installed, each in a different directory, and none of them worked with your method. However if I changed the path in mine it worked every time.

I understand it will not work in a "general" way, but I think most people can understand changing a path.

#15

hass - September 15, 2009 - 20:33

I was not able to get "%~dp0drush.php" working, but also tried it... haven't had the time to dig deeper why. "%0\..\drush.php" works, but now looking on the double quotes this should be added, too only to be save than sorry.

#16

legion80 - September 18, 2009 - 14:38

Try prepending an echo line and see if the path makes sense. This is what the drush.bat should look like

echo %~dp0drush.php
@php.exe "%~dp0drush.php" %1 %2 %3 %4 %5 %6 %7 %8 %9

#17

legion80 - September 18, 2009 - 15:02

Haven't seen this applied to the latest HEAD, so here's a patch for it.

AttachmentSize
drush.bat_.2057074.patch 258 bytes

#18

moshe weitzman - September 23, 2009 - 02:09

could someone review the latest patch?

#19

hass - September 23, 2009 - 07:26

Hasn't worked for me.

#20

vegemite4me - September 23, 2009 - 09:40

#10 worked for me.

#21

legion80 - September 23, 2009 - 18:35

@hass You said that %0 worked for you but %~dp0 didn't. Did you try my suggestion and echo out the output for both? Do you mind posting the results of "%0\..\drush.php" and "%~dp0drush.php"?

#22

awolfey - September 26, 2009 - 16:31

Patch + #10 works for me.

#23

manasiv - October 5, 2009 - 23:20

The patch in #17 by legion80 works for me.

#24

moshe weitzman - October 6, 2009 - 00:34
Status:needs review» fixed

#25

alexanderpas - October 13, 2009 - 22:59
Title:Could not open input file. drush.php» windows batch improvement (was: Could not open input file. drush.php)
Status:fixed» needs review

appending to this issue, as it is already referenced inside the batch file.

The %* batch parameter is a wildcard reference to all the arguments, not including %0, that are passed to the batch file.

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs...

AttachmentSize
drush-506448-25.patch 452 bytes

#26

moshe weitzman - October 22, 2009 - 03:45

is there something to do here?

#27

legion80 - October 30, 2009 - 04:43

i think this might just be an improvement over the last version, in that all of the arguments that were included in the drush command are passed to the .php file, rather than the first 9 arguments.

i have not tested this yet, but if this works, then i think this should be applied.

#28

moshe weitzman - November 1, 2009 - 11:49

Can anyone confirm that this most recent patch works?

 
 

Drupal is a registered trademark of Dries Buytaert.