Clear questions and runnable code
get the best and fastest answer
$? set to strange values on failure under Win32by pjf (Curate)
|on Jul 07, 2007 at 07:15 UTC||Need Help??|
pjf has asked for the
wisdom of the Perl Monks concerning the following question:
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:
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.
Perl Training Australia