italdesign has asked for the wisdom of the Perl Monks concerning the following question:
(Updated for clarity)
The idea is to encapsulate all the IPC work in that class. However, if I do this in the main program:package IPC_Class use strict; use warnings; sub new { shift; my $self = { 'cmds' => undef, @_ }; defined $self->{'cmds'} or die "ERROR: didn't get CMD in constructor +."; IPC::Shareable->clean_up_all; bless $self; return $self; } sub start { my $self = shift; my $fh_glob_ref = shift; ... # the cmd "grep 'zzz'" in the next line will fail. my $h = IPC::Run::start(['sort'], '<pipe', $fh_glob_ref, '|', ['grep +', 'zzz'], '>', $writefh, "2>", $writefh) or die "Error: $!\n"; $self->{'h'} = h; } sub finish { my $self = shift; $h = $self->{'h'}; if (!$h->finish()) { for ($h->full_results) { print "$_\n" }; } }
Assuming I gave it a cmd that resulted in an exit code other than 0, $h->finish() should test false and $h->full_results should show the exit code for each cmd. This is not happening. Instead I get "unknown result, unknown PID" for each member of $h->full_results. Now, if I move the code in finish() to the main program, then it works as expected, i.e. $h->full_results does show the exit codes including the failed one. So for some reason, finish() doesn't seem to be getting the proper $h object. Would appreciate any pointer.my $o = new IPC_Class; $o->start(\*FH_GLOB); # pass in a FH ref so we can pump more data to i +t later. # Now, add more data thru the FH. print FH_GLOB "line 1\n"; print FH_GLOB "line 2\n"; ... $o->finish();
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: IPC::Run harness question
by kcott (Archbishop) on May 03, 2014 at 06:05 UTC | |
by italdesign (Novice) on May 05, 2014 at 20:29 UTC | |
by kcott (Archbishop) on May 06, 2014 at 07:25 UTC | |
by italdesign (Novice) on May 06, 2014 at 21:51 UTC |