Wise monks,

I've been spending my time recently working upon a new revision of IPC::System::Simple, a module designed to take the headache out of calling external commands. Unfortunately, I've hit a snag under Windows.

My Windows system (WinXP, ActivePerl 5.8.8) appears to assign a value of 1 << 8 to $? upon failure to start a process. The following example demonstrates this:

system("this_command_does_not_exist",1); printf("raw: %d ; apparent exit: %d\n",$?, $?>>8);

Unfortunately, this is indistinguishable from the command running to completion and returning an exit status of 1. Not being able to tell the difference is a very bad thing. There's also a troublesome error message that is printed ('...' is not recognised as an internal or external command) that I assume is from the Windows shell, and ideally I'd love to supress the printing of this message.

Using the multiple argument version of system does not alter these results.

I'm sure there must be a way under Windows to tell if a command did not start, and it's probably something simple, but I'm at a loss to find it.

Any tips and pointers would be greatly appreciated.

Update: This problem isn't exactly unique to Windows. When using single-argument system() under Unix with shell meta-characters, the result in $? reflects the exit value of the shell, which returns 127 on a failure to find the command. This is indistinguishable from a successfully executed command returning an exitval of 127.


In reply to $? set to strange values on failure under Win32 by pjf

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.