Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All: I'm using a file handle to pipe a shell script execution.
my $jobfh = FileHandle->new; $jobfh->open("myshscript 2>&1 |");
Later I do some post processing like:
while(defined ($line = $jobfh->getline)) { # do something }
Finally, I need the correct exit code of the shell script. I always get 1 if I do:
$status = $jobfh->close; print $status;
This is wrong. Can anyone please let me know how to get the correct exit code from the file handle object. Thanks and best regards, Tony

Edited by Chady -- added code tags.

Replies are listed 'Best First'.
Re: exit code from FILEHANDLE object.
by haoess (Curate) on Jun 10, 2004 at 08:39 UTC

    You get 1 because close is successfull.

    Please have a look at $? in perlvar.