Using these two test progs:

process.pl

#!perl use strict; use warnings; my $exitCode = shift; print "will exit with $exitCode\n"; exit($exitCode);

shell.pl

#!perl use strict; use warnings; sub run_proc { my $code = shift; print "now running with $code\n"; my $status = system("process.pl $code"); my $exit_value = $status >> 8; my $signal_num = $status & 127; my $dumped_core = $status & 128; print <<"END_OF_STATUS"; exit_value: $exit_value signal_num: $signal_num dumped_core: $dumped_core END_OF_STATUS } run_proc(123); run_proc(-1); run_proc(255); run_proc(-5); run_proc(251);

I obtain these results with ActivePerl 5.8.3.809 on Windows 2000 (binary release):

now running with 123 will exit with 123 exit_value: 123 signal_num: 0 dumped_core: 0 now running with -1 will exit with -1 Can't spawn "cmd.exe": No such file or directory at c:\Exit value\shel +l.pl line 10. exit_value: 255 signal_num: 0 dumped_core: 0 now running with 255 will exit with 255 exit_value: 255 signal_num: 0 dumped_core: 0 now running with -5 will exit with -5 exit_value: 251 signal_num: 0 dumped_core: 0 now running with 251 will exit with 251 exit_value: 251 signal_num: 0 dumped_core: 0

The '-1' return code seems to have a special meaning. Sorry, I couldn't see why looking at perl's source code... You should give your perl -V results.

Anyway, I could get negative return code...


In reply to Re: How to get system -function negative return value? by dfaure
in thread How to get system -function negative return value? by Anonymous Monk

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.