Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

In windows, I'm invoking a command line application that returns integer (4 byte) exit codes. How can I read this exit code? Using $? >> 8 only let's me read the first of the four bytes.
  • Comment on Getting the errorlevel from a system call

Replies are listed 'Best First'.
Re: Getting the errorlevel from a system call
by thor (Priest) on Jun 18, 2004 at 21:42 UTC
    Maybe I'm missing something, but you say that you have an app that's returning a four-byte value, and yet $?>>8 is only letting you read the first four bytes. Wouldn't the first four bytes in a four-byte value constitute the entire value?

    thor

      "first of the four bytes" the op has said.

        eep...that's what I get for reading too fast. Now off to answer the original question.

        thor

Re: Getting the errorlevel from a system call
by thor (Priest) on Jun 18, 2004 at 23:15 UTC
    the $?>>8 construct shifts the $? value to the right by 8 bits. In order to examine the entire value, don't bit-shift it. However, perldoc perlvar has this to say about $?:
    This is just the 16-bit status word returned by the wait() system call (or else is made up to look like it).
    Where I come from, 16-bit values equate to 2-byte values, not four.

    thor