I have a class with 2 methods: start() and finish(). The relevant parts are below.

(Updated for clarity)

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" }; } }
The idea is to encapsulate all the IPC work in that class. However, if I do this in the main program:
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();
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.

In reply to IPC::Run harness question by italdesign

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.