Yes - see IPC::Open3. That module provides capturing STDERR of a command. The exit status is available after reaping the child with waitpid. Example (untested):
my $pid = open3('<&STDIN', \*CHLD_OUT, \*CHLD_ERR, "some_shell_express +ion"); while(<CHLD_OUT>) { # do something with that command's output } my $err = <CHLD_ERR>; # may block - better use select here waitpid $pid, 0; if ( $? ) { warn $_[0] . ($? == -1) ? "failed to execute: $!\n" : ($? & 127) ? sprintf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' : sprintf "child exited with value %d\n", $? >> 8; }
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
In reply to Re^3: Undestanding this code snippet
by shmem
in thread Undestanding this code snippet
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |