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



-- 
Tim Bolshaw

timothybols...@gmail.com
Mobile: +66-(0)87 072 5009
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to