On Tue, Jan 15, 2013 at 3:53 PM, David Cantrell <da...@cantrell.org.uk>wrote:
> On Tue, Jan 15, 2013 at 01:32:09AM -0800, Buddy Burden wrote: > > Gabor, > > > I am not sure if this helps but in Windows you need to put the > > > double-quotes around $cmd > > > > > > my $output = qx{$^X -e "$cmd"}; > > Yes, that would work if I were running _only_ on Windows. But I need > > it work for everything (and the double quotes on Linux will cause any > > variables in my perl code to get intepreted by the shell. :-/ > > Use the multi-argument form of system() to avoid all shell nastiness, > and use Capture::Tiny to catch its output. That problem is not shell nastiness. It is quoting. Observe: C:\Windows\system32>perl system($^X, '-le', 'print for @ARGV; die(qq/Oops/);'); __END__ Oops at -e line 1. C:\Windows\system32>perl system($^X, '-le', 'print for @ARGV; die("Oops");'); __END__ C:\Windows\system32> Where did my exception go? For that matter, where did my output go? What happened exactly? Did system() decide not to quote the final argument, since it contained quotes as well as spaces? Using C<< "echo" >> instead of C<< $^X >> suggests that's indeed how system behaves. :-\ Anyway ... If I recall correctly, the thing is that on Windows, a brand new process does not get an argument array. On Windows, it gets a command line. On Windows, the process gets to parse that command line. Now, system() does a better job building that command line than IPC::System::Simple does. But it does not get it "right". (And how could it, when every executable gets to implement its own command line parsing?) No, that's no way to go. On a more constructive note, either * write a command line as a Windows process expects it, and as suggested by several already; or * write a file (tempfile if needs be), and throw $^X at that instead. Eirik