Subject: | "POE::Wheel::Run[::Win32] example fails on Win32" |
Date: | Wed, 02 Sep 2009 14:48:47 -0400 |
To: | bug-poe [...] rt.cpan.org |
From: | Andrew Feren <acferen [...] yahoo.com> |
#!/usr/bin/perl
use warnings;
use strict;
my $wheel_run = 'POE::Wheel::Run'.(( $^O eq 'MSWin32' )?'::Win32':'');
use POE ( 'Wheel::Run'.( ( $^O eq 'MSWin32' ) ? '::Win32' : '') );
POE::Session->create(
inline_states => {
_start => \&on_start,
got_child_stdout => \&on_child_stdout,
got_child_stderr => \&on_child_stderr,
got_child_close => \&on_child_close,
got_child_signal => \&on_child_signal,
}
);
POE::Kernel->run();
exit 0;
sub on_start {
my $child = $wheel_run->new(
Program => [ "/bin/lsx", "-1", "/" ],
StdoutEvent => "got_child_stdout",
StderrEvent => "got_child_stderr",
CloseEvent => "got_child_close",
);
$_[KERNEL]->sig_child($child->PID, "got_child_signal");
# Wheel events include the wheel's ID.
$_[HEAP]{children_by_wid}{$child->ID} = $child;
# Signal events include the process ID.
$_[HEAP]{children_by_pid}{$child->PID} = $child;
print(
"Child pid ", $child->PID,
" started as wheel ", $child->ID, ".\n"
);
}
# Wheel event, including the wheel's ID.
sub on_child_stdout {
my ($stdout_line, $wheel_id) = @_[ARG0, ARG1];
my $child = $_[HEAP]{children_by_wid}{$wheel_id};
print "pid ", $child->PID, " STDOUT: $stdout_line\n";
}
# Wheel event, including the wheel's ID.
sub on_child_stderr {
my ($stderr_line, $wheel_id) = @_[ARG0, ARG1];
my $child = $_[HEAP]{children_by_wid}{$wheel_id};
print "pid ", $child->PID, " STDERR: $stderr_line\n";
}
# Wheel event, including the wheel's ID.
sub on_child_close {
my $wheel_id = $_[ARG0];
my $child = delete $_[HEAP]{children_by_wid}{$wheel_id};
# May have been reaped by on_child_signal().
unless (defined $child) {
print "wid $wheel_id closed all pipes.\n";
return;
}
print "pid ", $child->PID, " closed all pipes.\n";
delete $_[HEAP]{children_by_pid}{$child->PID};
}
sub on_child_signal {
print "pid $_[ARG1] exited with status $_[ARG2].\n";
my $child = delete $_[HEAP]{children_by_pid}{$_[ARG1]};
# May have been reaped by on_child_close().
return unless defined $child;
delete $_[HEAP]{children_by_wid}{$child->ID};
}
Attached is the example from the POE::Wheel::Run[::Win32]
documentation. I modified it by adding an 'x' to '/bin/ls' so the
command will fail on both *NIX and Windows.
On my *NIX box I get a reasonable error:
$ /usr/bin/perl wr.pl
Child pid 605 started as wheel 1.
pid 605 STDERR: can't exec (/bin/lsx -1 /) in child pid 605: No such
file or directory at /usr/local/share/perl/5.8.8/POE/Wheel/Run.pm
line 445.
pid 605 closed all pipes.
pid 605 exited with status 9728.
On Windows it appears to fail somewhere in POE with an obscure error:
C:\>perl wr.pl
Child pid -3584 started as wheel 1.
pid -3584 STDERR: Can't call method "get_next_priority" on unblessed
reference a
t C:/Perl/site/lib/POE/Resource/Events.pm line 68.
pid -3584 closed all pipes.
pid -3584 exited with status 2304.
If the 'Program' exists the script works as expected on both platforms.
My *nix perl has POE 1.007
My Win32 perl has POE 1.266
-Andrew