>
> All,
>
> I want to capture the exit value of a system call. How can I do this?
> My code is:
>
> system ( " cat /tmp/foo" );
> if ( $? == 0 ) {
>
> blah blah blah
> }
>
>
> I read the cookbook and it says :
>
> Both wait and waitpid return the process ID that they just reaped and
set $? to the wait status of the defunct process. This status is
actually two
> 8-bit values in one 16-bit number. The high byte is the exit value of the
> process. The low 7 bits represent the number of the signal that killed
the
> process, with the 8th bit indicating whether a core dump occurred. Here's
> one way to isolate those values:
> $exit_value = $? >> 8;
> $signal_num = $? & 127;
> $dumped_core = $? & 128;
>
So what don't you understand? C<$?> will be set automatically, using the
above code you can isolate the exit value as $exit_value. You have
seemingly answered your own question.
The
if ($? == 0)
Is actually not completely correct, it will only be correct on
(standard) success, better to use the 3 lines of code you provided, and
check the specific exit value.
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>