On Fri, Mar 8, 2013 at 2:49 AM, Dr.Ruud <rvtol+use...@isolution.nl> wrote:
> On 2013-03-07 10:21, WFB wrote:
>
>> waitpid($pid, 0);
>> close($trexe);
>> my $tr_ret = ($?>>8);
>
>
> Never postpone the reading of a global variable,
> just snapshot it as early as possible.
>
>   my $child = waitpid $pid, 0;
>   my $child_error = $?;  # snapshot a global
>
>   $child == -1 and die "No child with pid $pid found";
>
>   close $trexe or die "ERROR: $!";
>
>   my $tr_ret = ($child _error >> 8);
>

Or,  just eliminate the waitpid altogether since
there's an implicit waitpid when the pipe gets
closed. It gets a bit confusing but the pipe
close needs to be checked first and then
subsequently the child return as another poster
demonstrated:


   close $trexe or warn $! ? "Error closing $tr pipe: $!"
                            : "Exit status $? from $tr";

-- 
Charles DeRykus

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to