Hello hary536,

The following little scripts will help you to see what’s going on. Put them in the same directory:

#! perl # File: application.pl use strict; use warnings; my $code = $ARGV[0] // 0; printf "In application: result = '%5d' (decimal) or '%016b' (binary)\n +", $code, $code; exit $code;
#! perl # File: driver.pl use strict; use warnings; my $code = $ARGV[0] // 0; my @app = ('perl', 'application.pl', $code); my $result = system(@app); printf "In driver: result = '%5d' (decimal) or '%016b' (binary)\n +", $result, $result; printf " >> 8 = '%5d' (decimal) or '%016b' (binary)\n +", ($result >> 8), ($result >> 8);

Now, if you run, say,

perl driver.pl 255

from the command line, you should see this output:

In application: result = ' 255' (decimal) or '0000000011111111' (bina +ry) In driver: result = '65280' (decimal) or '1111111100000000' (bina +ry) >> 8 = ' 255' (decimal) or '0000000011111111' (bina +ry)

which shows that the return value from the application called via system has been left-shifted by 8 binary digits (i.e., multiplied by 256). See the Perl documentation entry for system, and also the explanation by Perlbotics in the recent post Re: getting the bash exit code.

Note that command line arguments are fed to system as a list, in this case supplied by the array @app in this line of driver.pl:

my $result = system(@app);
When I tried your above code, it always prints 255

The application is returning -1, which usually indicates failure. What happens when you run the application directly from the command line?

Hope that helps,

Athanasius <°(((><contra mundum


In reply to Re^3: How to catch the return code of another program? by Athanasius
in thread How to catch the return code of another program? by hary536

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.