http://www.perlmonks.org?node_id=692568

perlmonkey2 has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks. My question to those masters of Perlish wisdom pertains to POE::Wheel::Run on Win32. The code I'm posting is being ran on Win32 and seems to run up to the point where the parents event handler for the child's IO should trigger. Nothing happens. Well first let me explain what should happen. You start the app, a small widget pops up. You click the button, and the widget's label lets you know it worked, then a Wheel::Run is spun off which immediately prints to STDOUT, which should cause the stdout event handler to be triggered (which is what doesn't happen). So any clues/help would be greatly appreciated.
#!/usr/bin/perl -w use strict; use FileHandle; use Data::Dumper; use Gtk2 -init; use Gtk2::GladeXML; use POE::Kernel { loop => "Glib" }; use POE::Session; use POE::Wheel::Run; use POE::Filter::Line; use IO::Handle; autoflush STDOUT 1; autoflush STDIN 1; POE::Session->create( inline_states => { stdout => \&stdout, ev_clear => \&ev_clear, _start => \&_start, stderr =>\&stderr, error =>\&error, close =>\&close, } )->option(trace => 1,debug => 1); POE::Kernel->run(); exit(0); sub _start{ my ($session,$heap) = @_[ SESSION, HEAP]; $heap->{'gtk'} = Gtk2::GladeXML->new("poetest.glade"); $heap->{'gtk'}->get_widget('button1')->signal_connect( ( "clicked", $session->postback("ev_clear")) ); $heap->{'gtk'}->get_widget('mainwindow')->show_all; } sub ev_clear{ my ($session,$heap) = @_[SESSION,HEAP]; $heap->{'gtk'}->get_widget('label1')->set_text('worked'); $heap->{worker} = POE::Wheel::Run->new( Program => sub{ print "hello\r\n"; #my $line = <>; #print ">>$line<<\r"; my $io = new IO::Handle; if ($io->fdopen(fileno(STDOUT),"w")) { $io->print("It works\n"); } $io->close(); }, StdoutEvent => 'stdout', # Received data from the child +'s STDOUT. StderrEvent => 'stderr', # Received data from the child +'s STDOUT. ErrorEvent => 'error', CloseEvent => 'close', StdioFilter => POE::Filter::Line->new(), ); } sub stdout{ my ($arg,$heap) = @_[10,HEAP]; my $io = new IO::Handle; if ($io->fdopen(fileno(STDIN),"r")) { print $io->getline; $io->close; } print $arg,"\n\n\r"; $heap->{worker}->put("word yo\r"); } sub close{ print "child closed\n"; } sub error{ print "Just an Error\n"; } sub stderr{ my ($arg,$heap) = @_[10,HEAP]; print "Error $arg\n"; } __END__

20080618 Janitored by Corion: Restored node content

  • Comment on POE(::Wheel::Run) hates me (the lib, not the guy {as far as I know})
  • Download Code