in reply to Non-shell-invoking system/exec and qx//

Opening '-|' can take a list argument, so here's a substitute for backticks and readpipe given by ikegami in the thread CLASSPATH problem when using backticks:
sub backticks { open(my $pipe, '-|', @_) or return; local $/ = wantarray ? $/ : undef; <$pipe> }
Note that a shell could still get invoked if @_ == 1 and the first element contains shell metacharacters.

Replies are listed 'Best First'.
Re^2: Non-shell-invoking system/exec and qx//
by ikegami (Patriarch) on Jun 18, 2008 at 14:38 UTC

    Note that a shell could still get invoked if @_ == 1 and the first element contains shell metacharacters.

    Good point. And rather unfortunate. Many commands accept '--' as an argument to signify the end of the command line switches. You could pass that if you're executing such a program.

    backticks('ls foo'); # Run "ls" with argument "foo" backticks('ls foo', '--'); # Run "ls foo" with argument "--"
Re^2: Non-shell-invoking system/exec and qx//
by ikegami (Patriarch) on Jul 17, 2008 at 19:28 UTC
    IPC::System::Simple is an alternate solution that doesn't suffer from that bug.

    Update: Oops, didn't notice it was already mentioned below.