Re: Testing Success of Opening Pipe in Windows
Lyle <[email protected]> Sun, 12 Aug 2012 23:25:47 +0100
| Newsgroups | gmane.comp.lang.perl.active-perl |
|---|---|
| Message-ID | <[email protected]> |
Although your advice is probably sound (I haven't checked). I don't think that posting a link to an illegal copy of Programming Perl is fair on the authors, publisher, or the readers of this list. Lyle On 12/08/2012 22:11, Tim Bolshaw wrote: > Chapter 16.3 of /Programming Perl/ has a good basic explanation of how > to use pipes in Perl. (It is available online at > http://docstore.mik.ua/orelly/perl2/prog/ch16_03.htm if you do not yet > have a copy.) However, if you are doing extensive and complex > processing that relies on pipes, you will may find it easier to use > the Perl module IO::Pipe. > > Tim. > > > On Mon, Aug 13, 2012 at 3:48 AM, Edwards, Mark (CXO) > <[email protected] <mailto:[email protected]>> wrote: > > 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] > <mailto:[email protected]> > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > > > > > -- > Tim Bolshaw > > [email protected] <mailto:[email protected]> > Mobile: +66-(0)87 072 5009 > > > _______________________________________________ > ActivePerl mailing list > [email protected] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs