Please bottom post...

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

It is in *Perl*, but you are talking to an outside program. When you are
interacting with another program it can decide whatever it wants its
exit value to be, which is why 'system' can't decide. There is nothing
stopping me from writing a program such that,

if (0) {
  # false
  exit 0;
}
else {
  # true
  exit 1;
}

Then if you were to call my program it would exit with a "false" value
(one) even though it is always true!  The meaning of "true" is arbitrary
depending on context, and in this case it is the context of the program
you are calling, not Perl.

>From perldoc -f exit:

"The only universally recognized values for EXPR are 0 for success and 1
for error; other values are subject to interpretation depending on the
environment in which the Perl program is running.  For example, exiting
69 (EX_UNAVAILABLE) from a sendmail incoming-mail filter will cause the
mailer to return the item undelivered, but thatās not true everywhere."

And the terms "universally recognized" don't translate to "fact" ...
just ask Microsoft.

http://danconia.org


> 
> 
> "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
> > 
> > 
> > 
> > 
> > 
> 
> 
> 
> 
> 
> 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to