in reply to Re^3: Construct command portable way
in thread Construct command portable way
This is most weird. In your case, with the hard-coded perl, it works as expected (5.8.3 here). And the following fails, as supported by your assertion:
> perl -e"@cmd = ('perl ', '-le print for @ARGV', 'foo bar'); system @ +cmd" Der Befehl ""perl "" ist entweder falsch geschrieben oder konnte nicht gefunden werden.
But the following does not fail:
>perl -le "print $^X;@cmd = ($^X.' ', '-le print for @ARGV', 'foo bar' +); system @cmd" C:\Programme\Perl\bin\perl.exe foo bar
So my guess is that $cmd[0] is inspected for whitespace or quotes, and if it contains either, an intermediate shell is invoked. Which is just a horrible kludge, especially when most programs live (under some languages) under C:\Program Files\, which already contains whitespace. And there, quoting becomes necessary:
>perl -le "@cmd = (chr(34).$^X.' '.chr(34).' -le print+1 for @ARGV', ' +foo bar'); system @cmd" 1
It fails (properly) when the first parameter does not start with quotes, again:
>perl -le "@cmd = ($^X.' -le print+1 for @ARGV', 'foo bar'); system @c +md" Der Befehl ""C:\Programme\Perl\bin\perl.exe -le print+1 for @ARGV"" is +t entweder falsch geschrieben oder konnte nicht gefunden werden.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Construct command portable way
by ikegami (Patriarch) on May 07, 2009 at 11:12 UTC | |
|
Re^5: Construct command portable way
by repellent (Priest) on May 07, 2009 at 20:32 UTC | |
by parv (Parson) on May 08, 2009 at 01:35 UTC |