IPC::System::Simple provides $EXITVAL
, which captures the exit code of commands run via capture
and the other functions.
The exit value of any command executed by IPC::System::Simple can
always be retrieved from the $IPC::System::Simple::EXITVAL
variable:
This is particularly useful when inspecting results from capture,
which returns the captured text from the command.
use IPC::System::Simple qw(capture $EXITVAL EXIT_ANY);
my @enemies_defeated = capture(EXIT_ANY, "defeat_evil", "/dev/mordor");
print "Program exited with value $EXITVAL\n";
$EXITVAL
will be set to -1 if the command did not exit normally (eg,
being terminated by a signal) or did not start. In this situation an
exception will also be thrown.