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

I have this in a script:
my $code = system(q{apt-get -qq -o 'Debug::NoLocking=true' --simulate +upgrade}); print "code: "; print ($code & 127); print ";\n";
It returns 0 exit code:
code: 0;
But the command, run manually from the command line produces exit code 100:
$ apt-get -qq -o 'Debug::NoLocking=true' --simulate upgrade E: Unmet dependencies. Try using -f. $ echo $? 100
Why is this? How do I get the "real" return code?

Replies are listed 'Best First'.
Re: "system" returns different exit code than running the command from the command line
by moritz (Cardinal) on Jun 04, 2008 at 18:12 UTC
    quoting perldoc system:
    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

    And farther down:

    printf "child exited with value %d\n", $? >> 8;

    Is there any way the documentation could be clearer about it?

      Oh, I get it... I thought the "$code & 127" did the bit shifting. Blinders on I guess. Thanks.