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

The server had a disk problem in the past. Hmm. The command's exit code is 16. Could this provoke perl into closing the filehandle automagically?

I wasn't expecting perl to close a pipe-filehandle on a non-zero exitcode1, but that would explain what is going on: Can't close a non-existing filehandle.

1 My assumption: Either always close a pipe after exhausting the input or always leave it open.

P.S.: The raid has been rebuild successfully. The controller is just complaining that the failed disk has not been properly removed from it's configuration yet.

  • Comment on Re^2: close $fh fails on a single host - looking for explanation

Replies are listed 'Best First'.
Re^3: close $fh fails on a single host - looking for explanation
by Monk::Thomas (Friar) on Feb 13, 2014 at 11:51 UTC

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

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

    alternative solution: do not close the filehandle

      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