Testing Success of Opening Pipe in Windows
"Edwards, Mark (CXO)" <[email protected]> Sun, 12 Aug 2012 20:48:50 +0000
| Newsgroups | gmane.comp.lang.perl.active-perl |
|---|---|
| Message-ID | <B68A6BD7065456419FBE4F2BBF8595B77FB63503@G9W0723.americas.hpqcorp.net> |
The typical test for open is ...
open(HANDLE, "something _to_open") or die "Open failed, $!";
That works on Windows for a file but not a pipe.
$status=open(PIPE, "hostname |");
This works and I can read from the pipe but $status is always non-zero so I don't know whether it succeeds or fails. Even testing for $! or $? doesn't work. $? is always -1 and $! is always " Inappropriate I/O control operation". This works as expected on Unix be how do I test for success or failure of opening the pipe?
The first half of the code below works but I forced a failure on the second half
Code
----------------------------------------
use warnings;
use strict;
my($pid, $pipe);
print "Open pipe with real file\n";
$pid=open(PIPE, "hostname |");
print("OS Error: $!\n");
print("Child Error: $?\n");
print("PID: $pid\n");
print "Host Name:", <PIPE>;
close PIPE;
print "\n\n";
print "Open pipe with fake file to force a failure\n";
$pid=open(PIPE, "non_existent_file |");
print("OS Error: $!\n");
print("Child Error: $?\n");
print("PID: $pid\n");
print "Host Name:", <PIPE>;
close PIPE;
Output
----------------------------------------
======= Open pipe with real file
OS Error: Inappropriate I/O control operation
Child Error: -1
PID: 10464
Host Name:MEDWARDS5
====== Open pipe with fake file to force a failure
OS Error: Inappropriate I/O control operation
Child Error: -1
PID: 10468
'non_existent_file' is not recognized as an internal or external command,
operable program or batch file.
Host Name:
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs