Exitcode in Perl auswerten

aus PUG, der Penguin User Group
Wechseln zu: Navigation, Suche

Wenn man den Exitcode eines von Perl aufgerufenen externen Programms wissen will, muß man dazu den Rückgabewert um 8 Bits nach rechts shiften:

my $out=`/usr/local/bin/blahfasel`;
my $rc = $?>>8;

Die Information findet sich in man perlfunc bei der system-Funktion:

The return value is the exit status of the program as returned
by the "wait" call.  To get the actual exit value, shift right
by eight (see below). See also "exec".  This is not what you
want to use to capture the output from a command, for that you
should use merely backticks or "qx//", as described in
"‘STRING‘" in perlop.  Return value of -1 indicates a failure
to start the program or an error of the wait(2) system call
(inspect $! for the reason).