in reply to collect output of system()

If you want to completely avoid invoking a shell, try using IPC::Open2 (or IPC::Open3 if you also need stderr.) Using backticks will spawn a shell (there really should be a multi-argument form of backticks.)

Update: Here is a code fragment to do this:

use IPC::Open2; use File::Temp; my ($fh, $path) = tempfile(); unlink($path); # automatically releases storage on exit my $pid = open2($fh, \*STDIN, ’some', 'cmd', 'and', 'args'); waitpid $pid, 0; # wait for child to exit # now you can read the child's output from $fh

Replies are listed 'Best First'.
Re^2: collect output of system()
by vic (Initiate) on Feb 27, 2008 at 17:04 UTC