Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

POE::Wheel::Run & Tk Problems - Solved

by cmv (Chaplain)
on Aug 04, 2009 at 20:59 UTC ( [id://785898]=perlquestion: print w/replies, xml ) Need Help??

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

Update:
This turns out to be a problem in POE 1.006, that is fixed in POE 1.007. I've just updated to 1.007, and now I'm seeing the "dir" output in the console window. Running under 1.006 I didn't see that. Thanks to all for the help!

Helpful Monks-

I wish to use POE::Wheel::Run along with Tk to do some things.

As a starting point, I always like to grab the example code from the CPAN docs and start hacking on that.

The unmodified CPAN code runs fine as is on my various unix platforms. To get it to run under Activestate perl, I simply changed the Program line to be:

Program => 'dir',

and it also works fine.

The next step was to try to install the use Tk; at the beginning, so that POE could try to configure itself for the Tk event loop. Simply adding use Tk; before use POE; caused the program to fail on Activestate Perl (again it works fine on unix platforms).

Having a small bit of experience with these problems, I also tried use POE qw (Loop::TkActiveState); with no luck either. In addition, I did notice a POE::Wheel::Run::Win32, which I installed from Activestate and tried, but it failed even worse.

The script fails, by briefly flashing a blank Tk window, then exiting. The only output I see is the line "Child pid -2564 started as wheel 1."

Any help or pointers is appreciated!

Thanks

-Craig

PS - I'm attaching the code that I'm using in the following readmore tags, for completeness.

use warnings; use strict; use Tk; # Fails under Activestate, when this is uncommented #use POE qw( Loop::TkActiveState ); use POE; use POE::Wheel::Run; 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 = POE::Wheel::Run->new( Program => 'dir', 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}; }

Replies are listed 'Best First'.
Re: POE::Wheel::Run & Tk Problems
by Anonymous Monk on Aug 05, 2009 at 01:01 UTC
Re: POE::Wheel::Run & Tk Problems
by rcaputo (Chaplain) on Aug 05, 2009 at 04:22 UTC

    The last time I looked (which I admit is forever ago), "dir" was not a program in Windows (or DOS before it). Rather, it's a built-in shell command. You should try some actual program that will emit console output, but to be honest I don't know one off the top of my head.

    Alternatively, I'm pretty sure CMD.EXE (your shell) has some options to execute built-in commands. I just don't know what they are these days.

    It may also be worth testing whether you can execute batch files without starting a new shell.

    Of course, it may be something completely different, but that's where I'd start.

      Your post piqued my curiosity. I haven't used Windows in 10 years, so I thought I'd do a little review. I started with the dir command. Evidently, DOS does have a dir command. You can see it's documentation for 95, 98, ME here.

      Linux has a dir command also, but I'm not sure if all distros have it. The dir command appears to be just like ls, and it's written by the authors of ls, Richard Stallman and David MacKenzie.

      Update: It works on Vista too.

        Well, sure. It would be silly for an operating system to be unable to list directory contents. CMD.EXE has a built-in "dir" command, but there is no actual DIR.EXE or DIR.COM program in the version I just checked.

        Nevertheless, system() seems able to execute shell built-ins on Windows:

        C:\>perl -wle "system('set')" ALLUSERSPROFILE=C:\Documents and Settings\All Users
        Whereas this sort of thing fails in UNIX:
        % perl -wle 'system "set"' Can't exec "set": No such file or directory at -e line 1.

      The program works for me (activeperl 5.8.9, winxp), in that it starts, pops up a window, and console shows dir output, then after pid -1492 closed all pipes., it segfaults.
        If I remember correctly, you may have to invoke the "Program Compatibilty Advisor" on XP and Vista. Try that.
        Thank you for this feedback. When I run it, I don't see the dir output on the console (like I do when the use Tk is commented out). This may point to a version problem.

        I'm on winxp activeperl 5.8.9 build 825 (288577), using POE 1.006 and POE::Wheel::Run 0.16.

        I may try upgrading to POE 1.007 and see if that helps.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://785898]
Approved by AnomalousMonk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-23 07:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found