I am working with POE, win32 and ActiveState. I need to implement event driven fork/ exec. POE::Wheel::Run says, that ActiveState Perl doesn't like this module one bit.. So what's next?

I created an event, which utilizes Win32::Process within the following process flow:
- PROCESS 1 (LEFT) --------- - PROCESS 2 (RIGHT) ------- ----------- | POE:event | ----------- | V ------------------------ | Win32::Process::Create | ------------------------ \ (1) ------------------------- | -----> | 1) system( target ) \\ | |(2) | 2>stdout.txt 2>&1 | V | 2) print #eof# to | ------------------------ | stdout.txt | | POE::Wheel::FollowTail | ------------------------- | of file stdout.txt | <--- ------------------------ | |(3) | V no | ------------------- | | got line #eof# in | --------- | stdout.txt | ------------------- | yes V ------- | end | -------
Remarks:
  1. Reason for this is, that I was not able to pipe stdout and stderr to a file using Win32::Process::Create. Question: Do you know how to pipe stdout/ stderr with Win32::Process?
  2. I want to follow the target process' output. It is extremely important that multiple users cann follow the output. Hence, I need to create an output stream (file stdout.txt). Now I can create a POE::Wheel::FollowTail for every user interested in the target process' stdout and stderr.
  3. The POE::Wheel::FollowTail needs to know when there is no further output. Either process 2 (right side) needs to use POE's inter-kernel-communication (POE::Component::IKC) to inform process 1 (left side) about the process termination (system call is done). I thought, adding some #eof# indicator is much simpler.

Question is:

Since process 2 (right side) is kind of a child process, the process itself must be controlled by process 1 (left side) acting as a parent process. I have the process id of process 2 (right side) available via Win32::Process -> GetProcessID() and I can perform a Win32::Process -> Kill. But this leaves the target-process triggered by the system call alive. This target-process is the critical process. All other processes are wrappers. How to kill this process on a win32? Please consider the following issues: Help of the Perl/ POE community is very welcome. But I think, this is more a Perl question, since POE acts only as the environment.

If you really need some code fragments then
sub server_executeStart { my ($self, $kernel, $heap) = @_[ OBJECT, KERNEL, HEAP ]; # [ ... ] (snip) # # trigger win32::process my $cmd = sprintf 'perl Message/exec.pl --command="%s" --parameter +="%s" --stdout="%s"', $node -> { command }, $node -> { parameter }, $node -> { stream }; &debug( 'Spawning [%s]', $cmd ); my $proc; if (!Win32::Process::Create( $proc, $^X, $cmd, 0, CREATE_NO_WINDOW +, "." )) { &debug( 'win32 error: [%s]', Win32::FormatMessage( Win32::GetL +astError() ) ); $self -> { win32error } = 1; } # [ ... ] (snip) # # inform the client about execution start $kernel -> post( 'IKC', 'post', "poe://$clientKernel/$clientSession/executeStart", [ ] ); # next state: execution control $kernel -> yield( 'executeControl' ); } sub server_executeControl { my ($self, $kernel, $heap) = @_[ OBJECT, KERNEL, HEAP ]; # [ ... ] (snip) # # Creating follow wheel for $file (process stdout/ stderr) POE::Session -> create( inline_states => { _start => sub { my ($heap) = @_[ HEAP ]; $heap -> { follow } = POE::Wheel::FollowTail -> new( Filename => $file, InputEvent => 'gotLine', Seek => 0, PollInterval => '#eof', ); }, gotLine => sub { my ($kernel, $heap, $line) = @_[ KERNEL, HEAP, ARG +0 ]; if ($line =~ /^\#eof\#$/) { # remove the wheel $heap -> { follow } -> DESTROY; delete $heap -> { follow }; } else { # Received $line, so inform the client about i +t $kernel -> post( 'IKC', 'post', "poe://$clientKernel/$clientSessio +n/executeControl", [ $line ] ); } }, }, ); }

The Message/exec.pl looks similar to this
#!perl my $cmd = sprintf '"%s" %s 1>"%s" 2>&1', $opt { command }, $opt { parameter }, $opt { stdout }; system( $cmd ); # indicate EOF open( FILE, ">>", $opt { stdout } ); print FILE "#eof#\n"; close( FILE );
Thanks in advance.
mr.

In reply to POE and Win32::Process control by m-rau

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.