in reply to need both from system-call

Upps I discovered $?. But there is a strange behavior in the following codes:
xx.pl:
#!/usr/bin/perl print"STATUS:$?\n"; $result=`./xxx.pl`; $status=$?; print "RES:$result\nSTA:$status\n";
xxx.pl:
#!/usr/bin/perl print"Wonderful world on Friday\n"; exit 200;
This results in:
STATUS:0 RES:Wonderful world on Friday STA:25600
Why ???
Is 255 the return code from the second #!/usr/bin/perl ?
I'm a little bit confused ...
----------------------------------- --the good, the bad and the physi-- -----------------------------------

Replies are listed 'Best First'.
Re: Re: need both from system-call
by birdbrane (Chaplain) on Apr 27, 2001 at 16:20 UTC
    Look under "exit status" of the camel book. $? is the entire 16 bit status code. You only want the last 8 bits.

    This will fix your code: $status = $? >> 8; bb

Re: Re: need both from system-call
by hdp (Beadle) on Apr 27, 2001 at 16:20 UTC
    As perlvar documents, $? is "just the 16-bit status word returned by the wait() system call (or else is made up to look like it). Thus, the exit value of the subprocess is really ('$? >> 8')". It looks like perl thinks the exit value it got was 100.

    hdp.