system, exec, open '|-', open2, etc. all allow me to specify the command to run as a list of arguments that will be passed directly to execvp instead of run through a shell.
Even if perl is smart enough to run it directly if it looks like a "simple" command, that saves me the trouble of correctly shell-escaping the arguments with all the nasty pitfalls that it entails.
Example:
open my $out, '|-', $prog, @args;
system $prog, @args;
exec $prog, @args;
instead of
open my $out, "|$prog @args";
system "$prog @args";
exec "$prog @args";
Is there such an equivalent for the qx// operator? Or do you have to always do it by hand eg.
sub slurpcmd {
open my $h, '-|', @_ or die "open $_[0]|: $!";
local $/ unless wantarray;
<$h>
}
It turns out that (unfortunately) this wasn't an overlook from my part -- the only solution really is to do it with
open -|or use one of the external modules listed in the other answers.The backtick implementation (whether invoked by
qx/.../,`...`, orreadpipe) is deep down hardwired to accept a single string argument:Notice the
POPpconstxwhich pops a single argument from the stack and the use ofPerlProc_popeninstead ofPerlProc_popen_list.