public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Timothy Madden <terminatorul@gmail.com>
To: cygwin@cygwin.com
Subject: Re: Pass windows-style paths to the interpreter from the shebang line ?
Date: Thu, 10 Nov 2011 10:43:00 -0000	[thread overview]
Message-ID: <j9g9rn$hfh$1@dough.gmane.org> (raw)
In-Reply-To: <454021696.20111110052723@mtu-net.ru>

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

  parent reply	other threads:[~2011-11-10 10:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-09 13:40 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 [this message]
2011-11-10 14:20     ` Andrey Repin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='j9g9rn$hfh$1@dough.gmane.org' \
    --to=terminatorul@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).