delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/11/10/05:43:41

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RP_MATCHES_RCVD,SPF_HELO_PASS
X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Timothy Madden <terminatorul AT gmail DOT com>
Subject: Re: Pass windows-style paths to the interpreter from the shebang line ?
Date: Thu, 10 Nov 2011 12:43:03 +0200
Lines: 68
Message-ID: <j9g9rn$hfh$1@dough.gmane.org>
References: <j9dvqh$u92$1 AT dough DOT gmane DOT org> <454021696 DOT 20111110052723 AT mtu-net DOT ru>
Mime-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0
In-Reply-To: <454021696.20111110052723@mtu-net.ru>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019