public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Pass windows-style paths to the interpreter from the shebang line ?
@ 2011-11-09 13:40 Timothy Madden
  2011-11-09 15:30 ` Corinna Vinschen
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Timothy Madden @ 2011-11-09 13:40 UTC (permalink / raw)
  To: cygwin

Hello

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.

The problem is that bash will than invoke the Win32 native php.exe 
binary with the Cygwin-style path of my script as the argument,
and then php complains that it:

`Could not open input file: /home/Adrian/usr/local/bin/parseLog.php´

Which is normal for php.exe, as it does not understand cygwin paths.

I found no way around this problem. I would type `php /scriptname/´ 
myself but then the script name would no longer be searched on PATH and 
I would have to type 
'D:\Local\cygwin\home\Adrian\usr\local\bin\parseLog.php' as the script 
name at all times.

Is there a way around this ? Can cygwin detect the executable is not a 
cygwin application add pass in the right path name ?

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Pass windows-style paths to the interpreter from the shebang line ?
  2011-11-09 13:40 Pass windows-style paths to the interpreter from the shebang line ? Timothy Madden
@ 2011-11-09 15:30 ` Corinna Vinschen
  2011-11-09 15:46   ` Jeremy Bopp
                     ` (2 more replies)
  2011-11-09 15:51 ` Marco Atzeri
  2011-11-10  1:35 ` Andrey Repin
  2 siblings, 3 replies; 16+ messages in thread
From: Corinna Vinschen @ 2011-11-09 15:30 UTC (permalink / raw)
  To: cygwin

On Nov  9 15:39, Timothy Madden wrote:
> Hello
> 
> 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.
> 
> The problem is that bash will than invoke the Win32 native php.exe
> binary with the Cygwin-style path of my script as the argument,
> and then php complains that it:
> 
> `Could not open input file: /home/Adrian/usr/local/bin/parseLog.php´
> 
> Which is normal for php.exe, as it does not understand cygwin paths.
> 
> I found no way around this problem. I would type `php /scriptname/´
> myself but then the script name would no longer be searched on PATH
> and I would have to type
> 'D:\Local\cygwin\home\Adrian\usr\local\bin\parseLog.php' as the
> script name at all times.
> 
> Is there a way around this ? Can cygwin detect the executable is not
> a cygwin application add pass in the right path name ?

That's not as easy as it may sound.  What about creating wrapper scripts
with the same name in another dir and put that dir in front of the other
bin dir in $PATH?  The wrapper scripts could be shell scripts which use
`cygpath -wa' to convert the path to DOS notation and then call php.

I'm surprised that we don't have php in the Cygwin distro.  Did nobody
try to port php to Cygwin yet?


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Pass windows-style paths to the interpreter from the shebang line ?
  2011-11-09 15:30 ` Corinna Vinschen
@ 2011-11-09 15:46   ` Jeremy Bopp
  2011-11-09 15:51     ` Corinna Vinschen
  2011-11-09 21:16     ` Pass windows-style paths to the interpreter from the shebang line ? Timothy Madden
  2011-11-09 15:51   ` Jeremy Bopp
  2011-11-09 16:27   ` Andrew DeFaria
  2 siblings, 2 replies; 16+ messages in thread
From: Jeremy Bopp @ 2011-11-09 15:46 UTC (permalink / raw)
  To: cygwin

On 11/9/2011 09:29, Corinna Vinschen wrote:
> That's not as easy as it may sound.  What about creating wrapper scripts
> with the same name in another dir and put that dir in front of the other
> bin dir in $PATH?  The wrapper scripts could be shell scripts which use
> `cygpath -wa' to convert the path to DOS notation and then call php.
> 
> I'm surprised that we don't have php in the Cygwin distro.  Did nobody
> try to port php to Cygwin yet?

It looks like php is available in Cygwin Ports.  I've not tried it to
see how well it behaves though.

-Jeremy

--
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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Pass windows-style paths to the interpreter from the shebang line ?
  2011-11-09 15:30 ` Corinna Vinschen
  2011-11-09 15:46   ` Jeremy Bopp
@ 2011-11-09 15:51   ` Jeremy Bopp
  2011-11-10  1:35     ` Andrey Repin
  2011-11-09 16:27   ` Andrew DeFaria
  2 siblings, 1 reply; 16+ messages in thread
From: Jeremy Bopp @ 2011-11-09 15:51 UTC (permalink / raw)
  To: cygwin

Sorry to reply again, but I hit send too early...

On 11/9/2011 09:29, Corinna Vinschen wrote:
> That's not as easy as it may sound.  What about creating wrapper scripts
> with the same name in another dir and put that dir in front of the other
> bin dir in $PATH?  The wrapper scripts could be shell scripts which use
> `cygpath -wa' to convert the path to DOS notation and then call php.

Does php not have an equivalent of the -S option (search the PATH for
the named script) that perl and ruby have?  I've used that many times to
deal with cases where people have Windows-native builds of those tools
instead of the Cygwin ones for whatever reason.

-Jeremy

--
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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Pass windows-style paths to the interpreter from the shebang line ?
  2011-11-09 13:40 Pass windows-style paths to the interpreter from the shebang line ? Timothy Madden
  2011-11-09 15:30 ` Corinna Vinschen
@ 2011-11-09 15:51 ` Marco Atzeri
  2011-11-10  1:35 ` Andrey Repin
  2 siblings, 0 replies; 16+ messages in thread
From: Marco Atzeri @ 2011-11-09 15:51 UTC (permalink / raw)
  To: cygwin

On 11/9/2011 2:39 PM, Timothy Madden wrote:
> Hello
>
> 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.
>
> The problem is that bash will than invoke the Win32 native php.exe
> binary with the Cygwin-style path of my script as the argument,
> and then php complains that it:
>
> `Could not open input file: /home/Adrian/usr/local/bin/parseLog.php´
>
> Which is normal for php.exe, as it does not understand cygwin paths.
>
> I found no way around this problem. I would type `php /scriptname/´
> myself but then the script name would no longer be searched on PATH and
> I would have to type
> 'D:\Local\cygwin\home\Adrian\usr\local\bin\parseLog.php' as the script
> name at all times.
>
> Is there a way around this ? Can cygwin detect the executable is not a
> cygwin application add pass in the right path name ?
>
> Thank you,
> Timothy Madden
>

you need to use cygpath to convert posix path in window path

You could make a php.sh script like this to invoke your php.exe
with a window path

----------------------------------------------------------
#!/bin/bash
for i in $(echo $PATH | tr ':' ' ')
   do
     a=$(find  $i -name $1 -exec cygpath -w  \{\}    \;  )
     if ( [ "$a" != "" ] ) ; then
       /full_cygwin_path/php.exe $a
       exit
     fi
   done

----------------------------------------------------------

Regards
Marco



--
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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Pass windows-style paths to the interpreter from the shebang line ?
  2011-11-09 15:46   ` Jeremy Bopp
@ 2011-11-09 15:51     ` Corinna Vinschen
  2011-11-10  1:14       ` PHP (was: Re: Pass windows-style paths to the interpreter from the shebang line ?) Yaakov (Cygwin/X)
  2011-11-09 21:16     ` Pass windows-style paths to the interpreter from the shebang line ? Timothy Madden
  1 sibling, 1 reply; 16+ messages in thread
From: Corinna Vinschen @ 2011-11-09 15:51 UTC (permalink / raw)
  To: cygwin

On Nov  9 09:45, Jeremy Bopp wrote:
> On 11/9/2011 09:29, Corinna Vinschen wrote:
> > That's not as easy as it may sound.  What about creating wrapper scripts
> > with the same name in another dir and put that dir in front of the other
> > bin dir in $PATH?  The wrapper scripts could be shell scripts which use
> > `cygpath -wa' to convert the path to DOS notation and then call php.
> > 
> > I'm surprised that we don't have php in the Cygwin distro.  Did nobody
> > try to port php to Cygwin yet?
> 
> It looks like php is available in Cygwin Ports.  [...]

I should have known that.  Sorry Yaakov.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Pass windows-style paths to the interpreter from the shebang line ?
  2011-11-09 15:30 ` Corinna Vinschen
  2011-11-09 15:46   ` Jeremy Bopp
  2011-11-09 15:51   ` Jeremy Bopp
@ 2011-11-09 16:27   ` Andrew DeFaria
  2 siblings, 0 replies; 16+ messages in thread
From: Andrew DeFaria @ 2011-11-09 16:27 UTC (permalink / raw)
  To: cygwin

On 11/09/11 07:29, Corinna Vinschen wrote:
> I'm surprised that we don't have php in the Cygwin distro. Did nobody 
> try to port php to Cygwin yet? Corinna 
Hear, hear!
-- 
Andrew DeFaria <http://defaria.com>
Making music should not be left to the professionals. - Michelle Shocked


--
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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Pass windows-style paths to the interpreter from the shebang line ?
  2011-11-09 15:46   ` Jeremy Bopp
  2011-11-09 15:51     ` Corinna Vinschen
@ 2011-11-09 21:16     ` Timothy Madden
  2011-11-09 21:20       ` Christopher Faylor
  1 sibling, 1 reply; 16+ messages in thread
From: Timothy Madden @ 2011-11-09 21:16 UTC (permalink / raw)
  To: cygwin

On 09.11.2011 17:45, Jeremy Bopp wrote:
> On 11/9/2011 09:29, Corinna Vinschen wrote:
>> That's not as easy as it may sound.  What about creating wrapper scripts
>> with the same name in another dir and put that dir in front of the other
>> bin dir in $PATH?  The wrapper scripts could be shell scripts which use
>> `cygpath -wa' to convert the path to DOS notation and then call php.
>>
>> I'm surprised that we don't have php in the Cygwin distro.  Did nobody
>> try to port php to Cygwin yet?
>
> It looks like php is available in Cygwin Ports.  I've not tried it to
> see how well it behaves though.

I have the full cygwin distribution installed with setup.exe and no php ?

Where is the cygwin port for php ? Distributed separately ? Maintained 
separately ?

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Pass windows-style paths to the interpreter from the shebang line ?
  2011-11-09 21:16     ` Pass windows-style paths to the interpreter from the shebang line ? Timothy Madden
@ 2011-11-09 21:20       ` Christopher Faylor
  0 siblings, 0 replies; 16+ messages in thread
From: Christopher Faylor @ 2011-11-09 21:20 UTC (permalink / raw)
  To: cygwin

On Wed, Nov 09, 2011 at 11:15:47PM +0200, Timothy Madden wrote:
>On 09.11.2011 17:45, Jeremy Bopp wrote:
>> On 11/9/2011 09:29, Corinna Vinschen wrote:
>>> That's not as easy as it may sound.  What about creating wrapper scripts
>>> with the same name in another dir and put that dir in front of the other
>>> bin dir in $PATH?  The wrapper scripts could be shell scripts which use
>>> `cygpath -wa' to convert the path to DOS notation and then call php.
>>>
>>> I'm surprised that we don't have php in the Cygwin distro.  Did nobody
>>> try to port php to Cygwin yet?
>>
>> It looks like php is available in Cygwin Ports.  I've not tried it to
>> see how well it behaves though.
>
>I have the full cygwin distribution installed with setup.exe and no php ?
>
>Where is the cygwin port for php ? Distributed separately ? Maintained 
>separately ?

http://lmgtfy.com/?q=what+is+cygwin+ports

--
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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* PHP (was: Re: Pass windows-style paths to the interpreter from the shebang line ?)
  2011-11-09 15:51     ` Corinna Vinschen
@ 2011-11-10  1:14       ` Yaakov (Cygwin/X)
  2011-11-10 10:05         ` Corinna Vinschen
  0 siblings, 1 reply; 16+ messages in thread
From: Yaakov (Cygwin/X) @ 2011-11-10  1:14 UTC (permalink / raw)
  To: cygwin

On Wed, 2011-11-09 at 16:50 +0100, Corinna Vinschen wrote:
> On Nov  9 09:45, Jeremy Bopp wrote:
> > On 11/9/2011 09:29, Corinna Vinschen wrote:
> > > I'm surprised that we don't have php in the Cygwin distro.  Did nobody
> > > try to port php to Cygwin yet?
> > 
> > It looks like php is available in Cygwin Ports.  [...]
> 
> I should have known that.  Sorry Yaakov.

No problem, I've only been shipping it for four years now[1]. :-)

It's funny that this came up now.  I was just working on lining up the
new deps for Qt4, when I realized that the new QtSql deps and those I
would need to ITP php are practically the same.  I was actually debating
ITPing it and ITAing apache2 from Ports, if there is interest.


Yaakov

[1] http://cygwinports.blogspot.com/2007/10/php-on-cygwin.html



--
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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Pass windows-style paths to the interpreter from the shebang line ?
  2011-11-09 15:51   ` Jeremy Bopp
@ 2011-11-10  1:35     ` Andrey Repin
  0 siblings, 0 replies; 16+ messages in thread
From: Andrey Repin @ 2011-11-10  1:35 UTC (permalink / raw)
  To: Jeremy Bopp, cygwin

Greetings, Jeremy Bopp!

> Does php not have an equivalent of the -S option (search the PATH for
> the named script) that perl and ruby have?  I've used that many times to
> deal with cases where people have Windows-native builds of those tools
> instead of the Cygwin ones for whatever reason.

It does have a similar functionality. But this is not the real problem.


--
WBR,
Andrey Repin (anrdaemon@freemail.ru) 10.11.2011, <05:28>

Sorry for my terrible english...


--
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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Pass windows-style paths to the interpreter from the shebang line ?
  2011-11-09 13:40 Pass windows-style paths to the interpreter from the shebang line ? Timothy Madden
  2011-11-09 15:30 ` Corinna Vinschen
  2011-11-09 15:51 ` Marco Atzeri
@ 2011-11-10  1:35 ` Andrey Repin
  2011-11-10  9:46   ` Linda Walsh
  2011-11-10 10:43   ` Timothy Madden
  2 siblings, 2 replies; 16+ messages in thread
From: Andrey Repin @ 2011-11-10  1:35 UTC (permalink / raw)
  To: Timothy Madden, cygwin

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.


--
WBR,
Andrey Repin (anrdaemon@freemail.ru) 10.11.2011, <05:19>

Sorry for my terrible english...


--
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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Pass windows-style paths to the interpreter from the shebang line ?
  2011-11-10  1:35 ` Andrey Repin
@ 2011-11-10  9:46   ` Linda Walsh
  2011-11-10 10:43   ` Timothy Madden
  1 sibling, 0 replies; 16+ messages in thread
From: Linda Walsh @ 2011-11-10  9:46 UTC (permalink / raw)
  To: cygwin

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"

----
	So when he types in a script name at the Cygwin command line
is there something in bash that reads Windows file-associations and auto 
opens them ??

	Guess I haven't seen that 'extension'...


--
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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: PHP (was: Re: Pass windows-style paths to the interpreter from the shebang line ?)
  2011-11-10  1:14       ` PHP (was: Re: Pass windows-style paths to the interpreter from the shebang line ?) Yaakov (Cygwin/X)
@ 2011-11-10 10:05         ` Corinna Vinschen
  0 siblings, 0 replies; 16+ messages in thread
From: Corinna Vinschen @ 2011-11-10 10:05 UTC (permalink / raw)
  To: cygwin

On Nov  9 19:14, Yaakov (Cygwin/X) wrote:
> On Wed, 2011-11-09 at 16:50 +0100, Corinna Vinschen wrote:
> > On Nov  9 09:45, Jeremy Bopp wrote:
> > > On 11/9/2011 09:29, Corinna Vinschen wrote:
> > > > I'm surprised that we don't have php in the Cygwin distro.  Did nobody
> > > > try to port php to Cygwin yet?
> > > 
> > > It looks like php is available in Cygwin Ports.  [...]
> > 
> > I should have known that.  Sorry Yaakov.
> 
> No problem, I've only been shipping it for four years now[1]. :-)
> 
> It's funny that this came up now.  I was just working on lining up the
> new deps for Qt4, when I realized that the new QtSql deps and those I
> would need to ITP php are practically the same.  I was actually debating
> ITPing it and ITAing apache2 from Ports, if there is interest.

Personally I don't use either, but both would be certainly a valuable
addition to the Cygwin distro.  I'm just getting dizzy trying to count
the number of packages you maintain...


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Pass windows-style paths to the interpreter from the shebang line ?
  2011-11-10  1:35 ` Andrey Repin
  2011-11-10  9:46   ` Linda Walsh
@ 2011-11-10 10:43   ` Timothy Madden
  2011-11-10 14:20     ` Andrey Repin
  1 sibling, 1 reply; 16+ messages in thread
From: Timothy Madden @ 2011-11-10 10:43 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Pass windows-style paths to the interpreter from the shebang line ?
  2011-11-10 10:43   ` Timothy Madden
@ 2011-11-10 14:20     ` Andrey Repin
  0 siblings, 0 replies; 16+ messages in thread
From: Andrey Repin @ 2011-11-10 14:20 UTC (permalink / raw)
  To: Timothy Madden, cygwin

Greetings, Timothy Madden!

> 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/

Fine.

> For this to work, I think I need the shebang line.

For cygwin, seems so.

> 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

Yep. I haven't run into this issue myself, due to executing scripts from
current directory at all times... *shrugs*

> Now remember that "php" here is the native Windows port that can not 
> read that cygwin filename argument, begining with /home/adrian/...

The problem is not limited to php invocation, but also imposing restrictions
to the script usage.
If invocation issue could be solved by something like

$ cat /usr/bin/php
#! /bin/sh
/c/usr/php-win32/php.exe `cygpath --mixed $1` $*

You'd have to deal with PHP arguments as well.
Simple solution to the latter I could think about is to write a PHP library
converting Cygwin paths into native windows paths, where you know you need
them. Not where some supposedly sophisticated utility thinks you have them.

> The solutions I could think of include:
>         - compose a script named php, somewhere on PATH, written is sh,
>            perl, python, even php,

Naaah, you'd run into loop with PHP. :)

>         - 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.

There's pros and cons to use Cygwin ports when there's native version of the
same application is 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

Yep, it's not. Especially not if there's a custom loader in executable.

P.S.
Mixed paths would be safer to use inside Cygwin scripts. Just avoid using your
script with network share through UNC... :/


--
WBR,
Andrey Repin (anrdaemon@freemail.ru) 10.11.2011, <16:15>

Sorry for my terrible english...


--
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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2011-11-10 14:20 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-09 13:40 Pass windows-style paths to the interpreter from the shebang line ? Timothy Madden
2011-11-09 15:30 ` Corinna Vinschen
2011-11-09 15:46   ` Jeremy Bopp
2011-11-09 15:51     ` Corinna Vinschen
2011-11-10  1:14       ` PHP (was: Re: Pass windows-style paths to the interpreter from the shebang line ?) Yaakov (Cygwin/X)
2011-11-10 10:05         ` Corinna Vinschen
2011-11-09 21:16     ` Pass windows-style paths to the interpreter from the shebang line ? Timothy Madden
2011-11-09 21:20       ` Christopher Faylor
2011-11-09 15:51   ` Jeremy Bopp
2011-11-10  1:35     ` Andrey Repin
2011-11-09 16:27   ` Andrew DeFaria
2011-11-09 15:51 ` Marco Atzeri
2011-11-10  1:35 ` Andrey Repin
2011-11-10  9:46   ` Linda Walsh
2011-11-10 10:43   ` Timothy Madden
2011-11-10 14:20     ` Andrey Repin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).