John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

According to perlfunc, “The return value is the exit status of the program as returned by the wait call. To get the actual exit value shift right by eight.”

Meanwhile, the documentation for wait states, “...returns the pid of the deceased process, or -1 if there are no child processes.”

So, is the return result from system the same as the value of $?, or something different?

If the number given in exit of the child process is found by shifting right by 8, what interesting thing is in the low bits?

How’s that work on Windows systems? The documentation is written with a Unix-centric point of view, with the assumption that system is written in terms of exec instead of vice-versa.

—John

Replies are listed 'Best First'.
Re: return result from system ?
by iburrell (Chaplain) on Sep 04, 2003 at 19:05 UTC
    The return result of system is the $? value from wait. It also sets $?.

    The lower bits of the status code include flags to indicate if the process exited because of a signal or core dump. $? & 127 gives the signal number.

Re: return result from system ?
by sauoq (Abbot) on Sep 04, 2003 at 20:44 UTC

    You didn't read far enough in the documentation for wait¹: "The status is returned in "$?". (Emphasis added.)

    How’s that work on Windows systems?

    I suspect the behavior is emulated. I'd think that it would have to be for the sake of compatibility...

    1. It should probably read "wait(2)" in the perlfunc manpage, but since perl's wait() does the same thing, it doesn't much matter.

    -sauoq
    "My two cents aren't worth a dime.";