Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: close and autodie on pipes

by Athanasius (Chancellor)
on Jun 30, 2012 at 03:12 UTC ( #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";


Athanasius <°(((><contra mundum

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://979201]
[Corion]: Heh - a good talk on Youtube about why you want to keep your Genome as secret as possible (and not use it for vanity stuff like 23andme , or some ancestry stuff)

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2018-01-19 18:15 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (222 votes). Check out past polls.