Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: close and autodie on pipes

by Athanasius (Archbishop)
on Jun 30, 2012 at 03:12 UTC ( [id://979201]=note: print w/replies, xml ) Need Help??


in reply to close and autodie on pipes

From close in perldoc (emphasis added):

If the filehandle came from a piped open, close returns false if one of the other syscalls involved fails or if its program exits with non-zero status. If the only problem was that the program exited non-zero, $! will be set to 0.

So, by setting your pipe program to exit 1 you are ensuring that close() fails (i.e., returns false). autodie is working correctly here.

how should I check for errors?
#! perl use strict; use warnings; use autodie; open(my $fh, '-|', 'bash -c "echo Hello; exit 1"'); print <$fh>; { no autodie; unless (close($fh)) { die "Real pipe error: $!" if $!; } } print "status: ", ($? >> 8), "\n";

HTH,

Athanasius <°(((><contra mundum

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://979201]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-03-19 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found