From: Mark-Jason Dominus Date: Sat, 20 Apr 2002 03:36:28 +0000 (-0400) Subject: Re: [PATCH 5.7.3 docs] The question deals with a bug that was fixed X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=369c54331343defe7bfb462cf8cd06563be74d1b;p=p5sagit%2Fp5-mst-13.2.git Re: [PATCH 5.7.3 docs] The question deals with a bug that was fixed Message-ID: <20020420073628.324.qmail@plover.com> p4raw-id: //depot/perl@16031 --- diff --git a/pod/perlopentut.pod b/pod/perlopentut.pod index b158480..ebf57d5 100644 --- a/pod/perlopentut.pod +++ b/pod/perlopentut.pod @@ -89,7 +89,7 @@ command and open a write-only filehandle leading into that command. This lets you write into that handle and have what you write show up on that command's standard input. For example: - open(PRINTER, "| lpr -Plp1") || die "cannot fork: $!"; + open(PRINTER, "| lpr -Plp1") || die "can't run lpr: $!"; print PRINTER "stuff\n"; close(PRINTER) || die "can't close lpr: $!"; @@ -98,18 +98,20 @@ read-only filehandle leading out of that command. This lets whatever that command writes to its standard output show up on your handle for reading. For example: - open(NET, "netstat -i -n |") || die "cannot fork: $!"; + open(NET, "netstat -i -n |") || die "can't fun netstat: $!"; while () { } # do something with input close(NET) || die "can't close netstat: $!"; -What happens if you try to open a pipe to or from a non-existent command? -In most systems, such an C will not return an error. That's -because in the traditional C/C model, running the other -program happens only in the forked child process, which means that -the failed C can't be reflected in the return value of C. -Only a failed C shows up there. See -L -to see how to cope with this. There's also an explanation in L. +What happens if you try to open a pipe to or from a non-existent +command? If possible, Perl will detect the failure and set C<$!> as +usual. But if the command contains special shell characters, such as +C> or C<*>, called 'metacharacters', Perl does not execute the +command directly. Instead, Perl runs the shell, which then tries to +run the command. This means that it's the shell that gets the error +indication. In such a case, the C call will only indicate +failure if Perl can't even run the shell. See L to see how to cope with +this. There's also an explanation in L. If you would like to open a bidirectional pipe, the IPC::Open2 library will handle this for you. Check out