Problems? Is your data what you think it is? | |
PerlMonks |
Re^2: return value from system call, exit status, shift right 8, bitwise and, $?by Anonymous Monk |
on Feb 11, 2010 at 15:03 UTC ( [id://822664]=note: print w/replies, xml ) | Need Help?? |
Ok. I think I see now. If the system() call returns "-1", this is the same as a binary number of all 1's (since the system presumably uses the two's-complement representation), and it looks like it is:
So, if we get -1 back, then I can just stop checking bits right there. If the system() call does not return -1, but returns anything at all in those first 7 bits, then -- again -- I can stop checking anything else, because if those first 7 bits contain anything, that indicates that the program that was called received a signal and that's why it ended. Finally, if the system() call does not return -1, and those first 7 bits are all zeros, then only at that point do those next 8 bits contain anything of interest (the exit status of the program called). And to wrap this all up nicely, if the system() call returns 0, then that means all bits are off, thus:
and therefore the program that system() called evidently ran successfully. Thank you!
In Section
Seekers of Perl Wisdom
|
|