git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] change Perl syntax to support Perl 5.6

From
Avery Pennarun <apenwarr@gmail.com>
Date
Sep 2, 2008, 17:50 UTC
Message-ID
<32541b130809021050g22a7cb0blfde151844e6e8851@mail.gmail.com>
In-Reply-To
<32541b130809011723l1cd8abfid9228363f952875@mail.gmail.com>
On Mon, Sep 1, 2008 at 8:23 PM, Avery Pennarun <apenwarr@gmail.com> wrote:
Show 13 quoted lines
> 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
Previous: Avery PennarunNext: Junio C Hamano
Message 24 of 29 in “change Perl syntax to support Perl 5.6”
  1. change Perl syntax to support Perl 5.6Robert Schiele, Aug 30, 2008
  2. Jeff KingAug 30, 2008
  3. Junio C HamanoAug 30, 2008
  4. Jeff KingAug 30, 2008
  5. Robert SchieleAug 30, 2008
  6. Jeff KingAug 30, 2008
  7. Jakub NarebskiAug 30, 2008
  8. Robert SchieleAug 30, 2008
  9. Avery PennarunAug 31, 2008
  10. Randal L. SchwartzAug 31, 2008
  11. Junio C HamanoAug 31, 2008
  12. Avery PennarunAug 31, 2008
  13. Jakub NarebskiAug 31, 2008
  14. Petr BaudisAug 31, 2008
  15. H. Peter AnvinSep 1, 2008
  16. Robert SchieleSep 1, 2008
  17. Tom G. ChristensenSep 1, 2008
  18. Brandon CaseySep 4, 2008
  19. Tom G. ChristensenSep 5, 2008
  20. Jakub NarebskiAug 31, 2008
  21. Jay SoffianSep 1, 2008
  22. Alex RiesenSep 1, 2008
  23. Avery PennarunSep 2, 2008
  24. Avery PennarunSep 2, 2008
  25. Junio C HamanoAug 30, 2008
  26. Randal L. SchwartzAug 31, 2008
  27. Ask Bjørn HansenAug 31, 2008
  28. Junio C HamanoSep 1, 2008
  29. Junio C HamanoSep 1, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.