BrowserUk/Rob, your responses are gold. Your answers are exactly the sort of information I was after.
However it appears that $^E isn't yet my saviour. Under my Windows XP system I get the following results (uninitalized warnings trimmed):
#! perl -slw
use strict;
undef $^E;
undef $!;
print 'Successful command returning 1';
system 'c:/perl/bin/perl.exe -e"sleep 5; exit 1"';
print "![$!] ?[@{[$?, ':', $?>>8]}] E[$^E]";
undef $^E;
undef $!;
print "\nNonexistent command, attempted direct but fallback to via cmd
+";
system 'c:/doesNotExists.exe';
print "![$!] ?[@{[$?, ':', $?>>8]}] E[$^E]";
undef $^E;
undef $!;
print "\nNonexistent via cmd because 'shell chars'; sending stderr >nu
+ll";
system 'c:/doesNotExists.exe 2>null';
print "![$!] ?[@{[$?, ':', $?>>8]}] E[$^E]";
__END__
Successful command returning 1
![] ?[256 : 1] E[]
Nonexistent command, attempted direct but fallback to via cmd
'c:/doesNotExists.exe' is not recognized as an internal or external co
+mmand, operable program or batch file.
![No such file or directory] ?[256 : 1] E[]
Nonexistent via cmd because 'shell chars'; sending stderr >null
![] ?[256 : 1] E[]
It appears that redirecting stderr makes an unsuccessful command appear to be a successful command. When an error does occur, it's found inside $! and not $^E, which seems to never be set. Oh my!
Unfortunately this leaves me with the same tangle as Perl itself has in emulating system() under Windows. Ideally I want to preserve the following behaviours:
- Single argument call always goes via the shell
- Multi argument call never goes via the shell
- It's possible to tell when a command didn't start (ostensibly via $? being set to -1)
Using the shell means I don't have a reliable way of determining failure to start a command. Not using the shell means I may have to potentially go searching through $ENV{PATH} by hand.
I guess this is an excellent opportunity for me to go searching for that discussion by tye, and potentially go looking through Perl's source for system() under Windows. I suspect my final result will make heavy use of Win32:: modules to provide the required behaviour.
Many thanks again!
Update: Working with Win32::Process is showing great promise.
|