sorry about assuming!  Wait a second I though in Perl, a rc of 0 is false 
and 1 is true?

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145





"Wiggins d Anconia" <[EMAIL PROTECTED]>
08/27/2004 05:18 PM

 
        To:     [EMAIL PROTECTED], "Wiggins d Anconia" <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED]
        cc: 
        Subject:        Re: system call


Please bottom post....

> 
> yes I do understand but it is not working. 

You need to tell us that originally, we are not mind readers.

In other words when cat 
> /tmp/foo fails the blah blah blah is not ran. 

0 is success (in program return values *usually*), so if it fails, $?
will not == 0, so blah blah blah won't run.

> What I do not understand is the notes from the cookbook specifically 
$exit_value  = $? >> 8;
>
> How would I code this so that my if works b/c it sounds like to me as
the notes say the return code is two 8 
> bit values in one 16 bit number.
> 

The return result of system, aka $?, is a 16 bit number, with the 8 bit
exit value inside of it. So the >> shift operator will read the exit
value from $?, aka giving you just the 8 bits.  Then you test
$exit_value for 0, where 0 is success. So if you want to test failure, 

$exit_value = $? >> 8;
if ($exit_value) {
   # failure
}

*Assuming that the return value of 'cat' is sane, that is, that 0 is
success, this is convention rather than requirement. You will have to
check the docs for each individual program, aka cat in this case, for
what the exit values mean, if anything.

http://danconia.org


> 
> thank you , 
> Derek B. Smith
> OhioHealth IT
> UNIX / TSM / EDM Teams
> 
> 
> 
> 
> 
> 
> "Wiggins d Anconia" <[EMAIL PROTECTED]>
> 08/27/2004 04:12 PM
> 
> 
>         To:     [EMAIL PROTECTED], [EMAIL PROTECTED]
>         cc: 
>         Subject:        Re: system call
> 
> 
> > 
> > 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
> 
> 
> 
> 
> 




Reply via email to