in reply to detecting non-zero exit code when opening from a pipe
Full error checking and safer argument handling:
open(my $fh, '-|', 'gunzip', '-c', '--', $input_file) or die("Can't start gunzip: $!\n"); while (!eof($fh)) { defined($_ = <$fh>) or die("Error reading from gunzip: $!\n"); ... } close($fh) or die("Can't close gunzip: $!\n"); ($? & 0x7F) and die("gunzip died from signal ", ($? & 0x7F), "\n"); ($? >> 8) and die("gunzip exited with error ", ($? >> 8), "\n");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: detecting non-zero exit code when opening from a pipe
by Anonymous Monk on Oct 21, 2010 at 21:28 UTC | |
by ikegami (Patriarch) on Oct 21, 2010 at 22:49 UTC |