in reply to Re: detecting non-zero exit code when opening from a pipe
in thread detecting non-zero exit code when opening from a pipe

Hmm... didn't quite trap at the open statement.

>./errorcheck.pl notexists.gz gzip: notexists.gz: No such file or directory Can't close gunzip:

I guess the "Can't close gunzip" occurred due to a broken pipe?

Replies are listed 'Best First'.
Re^3: detecting non-zero exit code when opening from a pipe
by ikegami (Patriarch) on Oct 21, 2010 at 22:49 UTC

    Of course it didn't trap at the open statement. The error hasn't happened yet. As for the incorrect error message, the code should be:

    ... if (!close($fh)) { $! and die("Can't close gunzip: $!\n"); ($? & 0x7F) and die("gunzip died from signal ", ($? & 0x7F), "\n"); ($? >> 8) and die("gunzip exited with error ", ($? >> 8), "\n"); }
    gzip: notexists.gz: No such file or directory gunzip exited with error 1