git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Avery Pennarun" <apenwarr@gmail.com>
To: "Alex Riesen" <raa.lkml@gmail.com>
Cc: "Jakub Narebski" <jnareb@gmail.com>, "Jeff King" <peff@peff.net>,
	"Robert Schiele" <rschiele@gmail.com>,
	"Junio C Hamano" <gitster@pobox.com>,
	git@vger.kernel.org, "Lea Wiemann" <lewiemann@gmail.com>
Subject: Re: [PATCH] change Perl syntax to support Perl 5.6
Date: Tue, 2 Sep 2008 13:50:38 -0400	[thread overview]
Message-ID: <32541b130809021050g22a7cb0blfde151844e6e8851@mail.gmail.com> (raw)
In-Reply-To: <32541b130809011723l1cd8abfid9228363f952875@mail.gmail.com>

On Mon, Sep 1, 2008 at 8:23 PM, Avery Pennarun <apenwarr@gmail.com> wrote:
> On Mon, Sep 1, 2008 at 5:42 PM, Alex Riesen <raa.lkml@gmail.com> wrote:
>> Avery Pennarun, Sun, Aug 31, 2008 07:35:31 +0200:
>>> On Sat, Aug 30, 2008 at 4:37 PM, Jakub Narebski <jnareb@gmail.com> wrote:
>>> > Or you can use "open $fd, '-|'" to fork, an "manually" exec/system.
>>>
>>> Shell quoting is a disaster (including security holes, where relevant)
>>> waiting to happen.  The above is the only sane way to do it, and it
>>> isn't very hard to implement. ...
>>
>> except on Windows, where it is impossible to implement.
>
> True.  Although every program parses its own options on Windows, so
> proper, safe quoting is *also* impossible to implement.

Hmm, furthermore, perl seems to implement the "-|" operation just fine
on Windows.  I'm not really sure what it does, but it works.  Try the
attached perl script with the following command sequence.  (It works
on cygwin bash, but that might be magic; try it from cmd.exe instead
if you really want to reassure yourself.)

    echo >"foo blah"
    dir foo blah
         # above gives an error
    dir "foo blah"
         # above works
    c:\perl\bin\perl test.pl cmd /c dir "foo blah"
         # above works

Tested with ActiveState perl 5.6.1 (fails as "-|" is apparently not
supported *at all*, but maybe that's only on Windows), Cygwin perl
5.8.8 (works fine), and msysgit's perl 5.8.8 (works fine).

Now, as you can see above, the only copy of perl 5.6.x that I have
*didn't* work with this test, but it's on Windows, where I suspect
that version is just broken.  It says:

   '-' is not recognized as an internal or external command, operable
program or batch file.

You might then suspect that perhaps perl 5.6.1 didn't support the
open($fh, "-|") syntax at all, but 'perldoc perlipc' even on my
ActiveState perl 5.6.1 documents the feature.  Thus, I think it's
*just* the (obsolete) ActiveState version on Windows that has a buggy
implementation.  I would appreciate if someone with perl 5.6 on Linux
could try the program below with the commands above and see if it
works.

As another side note, the ActiveState perl *does* work if you call
fork() instead of open($fh, "-|"), but of course that doesn't redirect
stdin/stdout of the called process.  So perl on Windows *does*
correctly fake the fork/exec part.

test.pl follows.

Have fun,

Avery

P.S. Congratulations to the msysgit people for providing the only
version of msys perl that I could figure out how to install.


#!/usr/bin/perl -w
use strict;

if (@ARGV < 1) {
    print STDERR "Usage: $0 <command line...>\n";
    exit 127;
}

print "Arguments:\n{", join("}\n{", @ARGV), "}\n\n";

my $pid = open my $fh, "-|";
if ($pid) {
    # parent
    while (<$fh>) {
        s/\r?\n$//;
        chomp;
        print "[$_]\n";
    }
    my $newpid = waitpid($pid, 0);
    if ($newpid != $pid) {
        die("waitpid returned '$newpid', expected '$pid'\n");
    }	
    my $ret = $?;
    exit $? >> 8;
} else {
    # child
    exec(@ARGV);
}

# NOTREACHED

  reply	other threads:[~2008-09-02 17:51 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-30 17:39 [PATCH] change Perl syntax to support Perl 5.6 Robert Schiele
2008-08-30 18:00 ` Jeff King
2008-08-30 18:06   ` Junio C Hamano
2008-08-30 18:13     ` Jeff King
2008-08-30 18:34     ` Robert Schiele
2008-08-30 18:39       ` Jeff King
2008-08-30 20:37         ` Jakub Narebski
2008-08-30 21:21           ` Robert Schiele
2008-08-31  5:35           ` Avery Pennarun
2008-08-31 13:37             ` Randal L. Schwartz
2008-08-31 16:27               ` Junio C Hamano
2008-08-31 18:29                 ` Avery Pennarun
2008-08-31 20:23                   ` Jakub Narebski
2008-08-31 20:34                     ` Petr Baudis
2008-09-01  3:57                       ` H. Peter Anvin
2008-09-01  4:22                         ` Robert Schiele
2008-09-01 13:06                           ` Tom G. Christensen
2008-09-04 17:28                             ` Brandon Casey
2008-09-05  6:34                               ` Tom G. Christensen
2008-08-31 20:55                     ` Jakub Narebski
2008-09-01  1:52             ` Jay Soffian
2008-09-01 21:42             ` Alex Riesen
2008-09-02  0:23               ` Avery Pennarun
2008-09-02 17:50                 ` Avery Pennarun [this message]
2008-08-30 20:20       ` Junio C Hamano
2008-08-31 13:35 ` Randal L. Schwartz
2008-08-31 19:54 ` Ask Bjørn Hansen
2008-09-01  1:22   ` Junio C Hamano
2008-09-01  1:48     ` Junio C Hamano

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=32541b130809021050g22a7cb0blfde151844e6e8851@mail.gmail.com \
    --to=apenwarr@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jnareb@gmail.com \
    --cc=lewiemann@gmail.com \
    --cc=peff@peff.net \
    --cc=raa.lkml@gmail.com \
    --cc=rschiele@gmail.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 NNTP newsgroup(s).