[tpm] IO::Handle not catching errors

Indy Singh indy at indigostar.com
Mon May 26 20:42:27 PDT 2008


If the shell process exits with a non-zero status, the return value will
be found in $?.  You might need to call close first before you check $?.

A non-zero return code will not be an an IO error.  IO errors are not
very likely and I'm not sure if it is useful to worry about them.

An error in starting the shell process will be caught by the open call.

Indy Singh
IndigoSTAR Software -- www.indigostar.com


----- Original Message ----- 
From: "Madison Kelly" <linux at alteeve.com>
To: "Toronto Perl Mongers" <tpm at to.pm.org>
Sent: Monday, May 26, 2008 3:45 PM
Subject: [tpm] IO::Handle not catching errors


> Hi all,
>
>   I use IO::Handle for shell calls, and then check 'error' to see if
> there was an error. However, this isn't catching errors... Can someone
> clue me in?
>
> sub do_shell_call
> {
> my ($shell_call)=@_;
>
> my $sc=IO::Handle->new();
> print "  Shell call: [$shell_call]\n";
> open ($sc, $shell_call) or die "Shell call: [$shell_call] failed with
> error: $!";
> my $output=0;
> while (<$sc>)
> {
> if (!$output) { print "/----\n"; $output=1; }
> print "| $_";
> }
> if ($output) { print "\\----\n"; }
> if ($sc->error)
> {
> die "Shell call: [$shell_call] returned an error: $!";
> }
> $sc->close;
>
> return 0;
> }
>
> Madi
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
> 



More information about the toronto-pm mailing list