|more useful options|
RFC: IPC::System::Simple under Win32by pjf (Curate)
|on Jul 09, 2007 at 05:57 UTC||Need Help??|
I'm working on a number of improvements to IPC::System::Simple, a cross-platform module designed to take the headache out of calling system() and checking its returns. Unfortunately, I've hit a snag when it comes to the behaviour of system() under Windows.
The idea of IPC::System::Simple is that you can replace this (from perldoc -f system):
Currently this works very well, but it's currently got a small problem detecting errors on Win32 systems.
Put very simply, any call to system() under Windows will fall-back to using the shell if it can't execute the command directly. This occurs regardless of the number of arguments, or the presence or absence of shell metacharacters. The problem with using the shell is that on failure to start the given command it returns an exit value of 1, which is indistinguishable from a command successfully running and merely returning an exit value of 1.
The end result is that we can never really be sure if Window's system() has failed or not.
Interestingly enough, the exact same problem occurs under Unix, but Perl only uses the shell under Unix when it's called with a single argument, and then only when it contains metacharacters. When the Unix shell is used, we can't tell the difference between a command failing to start, and one that runs to completion and merely returns an exit value of 127.
I'm intending for IPC::System::Simple to always mimic the Unix behaviour of system, regardless of the platform used. In other words:
In the above examples, the first and third examples would be passed to the shell under Win32 if foo was not in the current working directory and we used system() instead. Neither would use the shell under Unix and modern releases of Perl.
One advantage of bypassing the shell is that we can also return the full 16-bit exit code returned by Windows processes. When using system() this is truncated to 8 bits.This RFC is intended primarily as a sanity check. I feel I have a compelling reason to deviate from Perl's behaviour of system() under Windows; the current implementation is inconsistent compared to its Unix counterpart, it fails in an ambiguous way, and loses bits of the return value. Can anyone find me a compelling argument not to do this? Further references:
Perl Training Australia