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

This is basically how I use IPC::Run::run and check for success and exit code:

... eval { IPC::Run::run \@cmd, '>>', $outfile, '2>&1'; }; if($@) { # Could not run the program $fail_to_run=$@; $exitcode=undef; } else { $fail_to_run=undef; $exitcode=$? >> 8; }
This piece of code is supposed to run under Unix and Windows. You will notice that I'm throwing away the low byte of $?. My understanding is that this would be not equal to zero only if the command could not be run, in which case run throws an exception anyway. On the cases I found so far, this seemed to be true: I never had a $? with low byte not zero. Can I rely on this, or do I have to evaluate $? & 0xff as well? Is there anything else I'm missing?

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re: Getting exit code after IPC::Run (Windows vs. Unix)
by jettero (Monsignor) on Aug 12, 2009 at 12:32 UTC
    I hate figuring out $? by hand... check out IPC::System::Simple, it makes it so you don't have to deal with that stuff at all.

    -Paul

      Thanks, I will have a look at it!

      -- 
      Ronald Fischer <ynnor@mm.st>
Re: Getting exit code after IPC::Run (Windows vs. Unix)
by cdarke (Prior) on Aug 12, 2009 at 13:02 UTC
    The low byte is used for the signal number which interrupted your child process, if any. It is not supported on Windows.

    Note also that Perl does not support Windows exit values > 255, even though the OS does.