Author image Roderick Schertler


Proc::SafePipe - popen() and `` without calling the shell


    $fh         = popen_noshell 'r', 'decrypt', $input;
    ($fh, $pid) = popen_noshell 'w', 'ssh', $host, "cat >$output";

    $all_output = backtick_noshell 'decrypt', $input;
    @lines      = backtick_noshell $cmd, @arg;


These functions provide a simple way to read from or write to commands which are run without being interpreted by the shell. They croak if there's a system failure, such as a failed fork.

popen_noshell mode command [arg]...

This function is similar to popen() except that the command and its related args are never interpreted by a shell, they are passed to exec() as-is. The mode argument must be 'r' or 'w'.

If called in an array context the return value is a list consisting of the filehandle and the PID of the child. In a scalar context only the filehandle is returned.

backtick_noshell command [arg]...

This function runs the given command with the given args and returns the output, like `` does. The difference is that the arguments are not filtered through a shell, they are exec()ed directly.

The return value is either all the output from the command (if in a scalar context) or a list of the lines gathered from the command (in an array context). The exit status of the command is in $?.


Roderick Schertler <>