R
Ryan
I'm using code similar to the following to run a command and grab the
output from both STDOUT and STDERR separately:
local (*IN, *OUT, *ERR);
my $pid = IPC::Open3:pen3(*IN, *OUT, *ERR, $cmd, @args);
print IN join "\n", @input;
close IN;
my @out = <OUT>;
my @err = <ERR>;
close OUT;
close ERR;
waitpid $pid, 0;
print "exit: $?\n"
Most of the time this works, but occasionally waitpid will return -1
and $? will also be set to -1 meaning that there is no child process.
Presumably the child exited before my call to waitpid.
What can I do to reliably grab the exit code?
Thanks,
-Ryan
output from both STDOUT and STDERR separately:
local (*IN, *OUT, *ERR);
my $pid = IPC::Open3:pen3(*IN, *OUT, *ERR, $cmd, @args);
print IN join "\n", @input;
close IN;
my @out = <OUT>;
my @err = <ERR>;
close OUT;
close ERR;
waitpid $pid, 0;
print "exit: $?\n"
Most of the time this works, but occasionally waitpid will return -1
and $? will also be set to -1 meaning that there is no child process.
Presumably the child exited before my call to waitpid.
What can I do to reliably grab the exit code?
Thanks,
-Ryan