On Mon, Sep 1, 2008 at 8:23 PM, Avery Pennarun <apenwarr@xxxxxxxxx> wrote: > On Mon, Sep 1, 2008 at 5:42 PM, Alex Riesen <raa.lkml@xxxxxxxxx> wrote: >> Avery Pennarun, Sun, Aug 31, 2008 07:35:31 +0200: >>> On Sat, Aug 30, 2008 at 4:37 PM, Jakub Narebski <jnareb@xxxxxxxxx> 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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html