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 ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs