you get -1 in case of any kind of execution error.

Not on Windows 2000, as you can see from my example. I don't know about XP or Vista. Maybe someone could try this out?

BTW, to get the return code on Windows 2000 (ActiveState Perl again - I don't know about Strawberry), you need to do a bit more logic than you posted, because you can't distinguish between a program execution error, and a program which runs fine but returns exit code 1. Here is what you have to do:

$!=0; system('your_program_goes_here'); my $child_error=$? & 0xff; my $maybe_exit_code=$? >> 8; if($child_error || ($maybe_exit_code && $!)) { # there was an error in program execution }
Also note that even if $?==0, it does not say that your program terminated with exit code 0. You get only the low 8 bit of the "real" Windows exit code, so if your program exited with a code which is a whole multiple of 256, you wouldn't notice it.
-- 
Ronald Fischer <ynnor@mm.st>

In reply to Re^2: system and $? by rovf
in thread system and $? by rovf

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.