<?xml version="1.0" encoding="windows-1252"?>
<node id="625392" title="$? set to strange values on failure under Win32" created="2007-07-07 03:15:02" updated="2007-07-06 23:15:02">
<type id="115">
perlquestion</type>
<author id="116014">
pjf</author>
<data>
<field name="doctext">
&lt;p&gt;
Wise monks,
&lt;/p&gt;&lt;p&gt;
I've been spending my time recently working upon a new revision of &lt;a href="http://search.cpan.org/perldoc?IPC::System::Simple"&gt;IPC::System::Simple&lt;/a&gt;,  a module designed to take the headache out of calling external commands.  Unfortunately, I've hit a snag under Windows.
&lt;/p&gt;&lt;p&gt;
My Windows system (WinXP, ActivePerl 5.8.8) appears to assign a value of &lt;tt&gt;1 &amp;lt;&amp;lt; 8&lt;/tt&gt; to &lt;tt&gt;$?&lt;/tt&gt; upon failure to start a process.  The following example demonstrates this:
&lt;/p&gt;
&lt;code&gt;
system("this_command_does_not_exist",1);
printf("raw: %d ; apparent exit: %d\n",$?, $?&gt;&gt;8);
&lt;/code&gt;
&lt;p&gt;
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 &lt;i&gt;very bad thing&lt;/i&gt;.  There's also a troublesome error message that is printed (&lt;i&gt;'...' is not recognised as an internal or external command&lt;/i&gt;) that I assume is from the Windows shell, and ideally I'd love to supress the printing of this message.
&lt;/p&gt;&lt;p&gt;
Using the multiple argument version of system does not alter these results.
&lt;/p&gt;&lt;p&gt;
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.
&lt;/p&gt;&lt;p&gt;
Any tips and pointers would be greatly appreciated.
&lt;/p&gt;&lt;p&gt;
&lt;b&gt;Update:&lt;/b&gt; This problem isn't exactly unique to Windows. When using single-argument &lt;tt&gt;system()&lt;/tt&gt; under Unix with shell meta-characters, the result in &lt;tt&gt;$?&lt;/tt&gt; 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.
&lt;/p&gt;
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-116014"&gt;
&lt;i&gt;Paul Fenwick&lt;/i&gt;&lt;br&gt;
&lt;a href="http://perltraining.com.au/"&gt;Perl Training Australia&lt;/a&gt;
&lt;/div&gt;&lt;/div&gt;</field>
</data>
</node>
