in reply to Re^2: close $fh fails on a single host - looking for explanation
in thread close $fh fails on a single host - looking for explanation

CONFIRMED. The non-zero exit code is the culprit.

implemented solution:
open my $fh, '-|', "$command || true"

alternative solution: do not close the filehandle

Replies are listed 'Best First'.
Re^4: close $fh fails on a single host - looking for explanation
by McA (Priest) on Feb 13, 2014 at 12:21 UTC

    Hi,

    culprit is the wrong term, because this is intended behaviour on UNIX like systems. Many people don't know that, but the return code of the command at the pipe sink is propagated through the return code of the close on that filehandle.

    Therefore it is not the best solution avoiding to close the filehandle, but be prepared for the valid return values.

    Hava a look at man 2 close and perldoc -f close.

    Best regards
    McA