delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/11/10/09:20:31

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=3.5 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,KAM_THEBAT
X-Spam-Check-By: sourceware.org
Date: Thu, 10 Nov 2011 18:14:31 +0400
From: Andrey Repin <anrdaemon AT freemail DOT ru>
Reply-To: Andrey Repin <cygwin AT cygwin DOT com>
Message-ID: <992045008.20111110181431@mtu-net.ru>
To: Timothy Madden <terminatorul AT gmail DOT com>, cygwin AT cygwin DOT com
Subject: Re: Pass windows-style paths to the interpreter from the shebang line ?
In-Reply-To: <j9g9rn$hfh$1@dough.gmane.org>
References: <j9dvqh$u92$1 AT dough DOT gmane DOT org> <454021696 DOT 20111110052723 AT mtu-net DOT ru> <j9g9rn$hfh$1 AT dough DOT gmane DOT org>
MIME-Version: 1.0
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

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 AT freemail DOT 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

- Raw text -


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