Pass windows-style paths to the interpreter from the shebang line ?

Timothy Madden terminatorul@gmail.com
Thu Nov 10 10:43:00 GMT 2011


On 10.11.2011 03:27, Andrey Repin wrote:
> Greetings, Timothy Madden!
>>> I would like to write a php script to run from my cygwin command line.
>> I have the php CLI executable (php.exe) in PATH and I use
>> #!/bin/env php
>> as the first line of the .php script, and make it executable.
>> Dearly use Windows native version of PHP
>> And here's a simple command file to register your PHP as script interpreter
> for both simple execution and windows scripting host jobs.
>> @echo off
> if "!%~dpnx1" == "!" (echo Usage: %~dp0 path_to_php-cli.exe&& exit)
> if not exist "%~dpnx1" (echo Invalid path to PHP interpreter&& exit)
> ftype PHPScript="%~dpnx1" -f "%%1" -- %%*
> assoc .php=PHPScript
> regsvr32 "%~dp1\php5activescript.dll"
>> If you still insist on using shebang, just use "#! php" without any additions.
> That assuming you have PHP in your application search path. Which is not
> limited to $PATH, so to speak.

As Linda said, I would like to be able to execute my new script from a 
cygwin prompt and from a sh script, with a command like
	parseLog.php	/logfile/
For this to work, I think I need the shebang line. So I tried "#! php" 
too, the problem is that bash will then invoke the following command to 
process my script:
	php /home/adrian/usr/local/bin/parseLog.php
Now remember that "php" here is the native Windows port that can not 
read that cygwin filename argument, begining with /home/adrian/...
For this to work, the native php needs the native path, so you would 
think I need to use *cygpath --mixed -- ...* or *cygpath --windows ...* 
on the script filename argument to get the right path for the php 
interpreter. The problem is there is hardly any way to do this in the 
shebang line, which is only limited to at most two arguments (usually 
the interpreter name followed by one option, or the /bin/env utility 
followed the interpreter name), and which is processed automatically by 
the shell, following a non-configurable procedure that does not include 
`cygpath --mixed -- ...` invocation.
The solutions I could think of include:
	- compose a script named php, somewhere on PATH, written is sh,
 perl, python, even php, or any other language, that finds the
	 real native php on PATH, parses the given command line
	 according to the php command line syntax, finds the filename
	 argument, if any, and convert that filename argument from the
	 cygwin style to mixed (or windows) style with cygpath. I find
	 this to be not a trivial task, so I wrote a simple one that
	 just treats the first argument as the script filename argument
	 and hard-codes the path to the native php.exe.
	- get a cygwin port of php, that understands cygwin-style paths
	 given on the command line. Although Cygwin setup.exe did not
	 install such a port, I am happy to find here that there still
 is a cygwin port of php available.
 - have the cygwin port of bash detect if the
	 interpreter binary from any shebang line is a cygwin
	 application or a native application and compose the command
	 line accordingly. Corinna Vinschen on this list says this is
	 not as easy as it sounds, though
Thank you,
Timothy Madden
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple


More information about the Cygwin mailing list

AltStyle によって変換されたページ (->オリジナル) /