Rocco Caputo wrote:
On Wed, Feb 12, 2003 at 08:38:25AM +1100, [EMAIL PROTECTED] wrote:

<snip>
It's a valid interpretation of ErrorEvent, but it's not the way
POE::Wheel::Run was written.

StdoutEvent, StderrEvent, and ErrorEvent refer to the pipes that
attach the parent and child processes.  The first two provide child
output that is received on those pipes, and the third lets you know if
there are errors reading from them.

A child program's return value comes to you differently: through
SIGCHLD.  If it's significant, you'll need to set up a SIGCHLD handler
and match the returned process ID against the process ID of your
active wheel.

  sub _start_handler {
    my $kernel = $_[KERNEL];
    $kernel->sig( CHLD => "sig_chld" );

    my $heap = $_[HEAP];
    my $wheel = POE::Wheel::Run->new( ... );

    # Map PID to wheel reference here.  Useful for managing multiple
    # child processes in the same session.
    $heap->{wheels}{$wheel->PID} = $wheel;
  }

  # ARG1 contains the PID of the ended child process.
  # ARG2 contains the $? (perlvar) associated with this CHLD signal.
  sub sig_chld_handler {
    my ($pid, $return_value) = @_[ARG1, ARG2];
    my $wheel = delete $_[HEAP]->{wheels}{$pid};
    if (defined $wheel) {
      print "Process $pid returned $return_value.\n";
    }
  }

Should the above be added to the POE::Wheel::Run docs or on the cookbook page possibly? I think this is a good example of what should be done, and was also confused by how the docs are worded. It also appeared to me that the "CloseEvent" was *the* way to find out that the process was complete, when clearly it is really just when STDOUT is closed, granted this should happen when the process is over. I haven't had a chance to work the above into my app yet but it definitely closes one question I had lingering....

http://danconia.org

Reply via email to