From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11989 invoked by alias); 10 Nov 2011 10:43:33 -0000 Received: (qmail 11978 invoked by uid 22791); 10 Nov 2011 10:43:32 -0000 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 Received: from lo.gmane.org (HELO lo.gmane.org) (80.91.229.12) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 10 Nov 2011 10:43:18 +0000 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1ROS6H-0003XX-Bd for cygwin@cygwin.com; Thu, 10 Nov 2011 11:43:17 +0100 Received: from 81-181-249-254.fo.opensys.ro ([81.181.249.254]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 10 Nov 2011 11:43:17 +0100 Received: from terminatorul by 81-181-249-254.fo.opensys.ro with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 10 Nov 2011 11:43:17 +0100 To: cygwin@cygwin.com From: Timothy Madden Subject: Re: Pass windows-style paths to the interpreter from the shebang line ? Date: Thu, 10 Nov 2011 10:43:00 -0000 Message-ID: References: <454021696.20111110052723@mtu-net.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2011-11/txt/msg00182.txt.bz2 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