On Wed, Feb 12, 2003 at 08:38:25AM +1100, [EMAIL PROTECTED] wrote:
> > That output indicates ErrorEvent has been triggered twice.  The first
> > time when the child process closes STDERR, and the second time when it
> > closes STDOUT.  I added some extra output to the sample code:
> 
> Based upon your earlier comments, this is as I had expected.  What does
> concern me however is that the dying of the executed program, which an
> associated error return value, is not triggering an error event.
> 
>     my $task = POE::Wheel::Run->new(
>         'Program'       =>  'perl -e "die"',
>         'CloseEvent'    =>  'close',
>         'ErrorEvent'    =>  'error',
>         'StderrEvent'   =>  'output',
>         'StdoutEvent'   =>  'output',
>         'StderrFilter'  =>  POE::Filter::Stream->new,
>         'StdoutFilter'  =>  POE::Filter::Stream->new
>     );
> 
> This I would expect should trigger an error event - Or are my expectations
> incorrect here?  Alternatively, what would be another way to obtain the
> return value for a program executed through POE::Wheel::Run?

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";
    }
  }

-- Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/

Reply via email to