Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

pjf (2464)

pjf
  (email not shown publicly)
http://pjf.id.au/
AOL IM: miyuki3k (Add Buddy, Send Message)
Jabber: pjf@jabber.org

I run Perl Training Australia [perltraining.com.au].

I help with Melbourne Perl Mongers.

I spend an awful lot of time talking about Perl, and have had my picture in the Australian newspapers with a camel. That's rather scary.

Journal of pjf (2464)

Saturday July 07, 2007
09:27 PM

$?, system() and win32

[ #33741 ]

$?, system() and win32
Warning: Technical post ahead.

I've been working on improvements to IPC::System::Simple, and discovered a tricky problem while writing more test cases. Put very simply, when using system() under Windows I'm unable to tell the difference between a command that we can't find, and one that we can find, but returns an exit value of 1.

The problem is two-fold. Firstly, whenever we invoke a shell to spawn a process, we can't ever tell the difference between the shell returning a "can't start" value, and a command that runs successfully and returns the same value. This isn't a problem that's unique to Windows; the "can't start" value is 1 under Windows, and 127 under Unix.

The second problem is Windows-Perl specific. If it fails to start the command successfully, it tries to invoke it using the shell, even if the multi-argument version of system() is used. This means that under Windows we can never tell the difference between a failed command and a completed command returning -1.

I suspect that Perl invoking the shell when using a multi-arg system call is a bug. If not, then it needs to be explicitly documented. Time for me to fire up perlbug again.

In the meantime, I can get around most of these things problems in IPC::System::Simple by falling back on the Win32::Process module. This is almost certainly the correct solution regardless of what happens with Windows system(), since it allows us to access the full 16-bit return value, something that system() will never do. Unfortunately it means that I need to do a lot of the work by hand that would normally be handled in Perl's win32.c, and I'm not really looking forward to that.

For further reading, see $? set to strange values under Win32.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.