yes I do understand but it is not working. In other words when cat /tmp/foo fails the blah blah blah is not ran. 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. 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