- 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 | ------- #### 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::GetLastError() ) ); $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, ARG0 ]; if ($line =~ /^\#eof\#$/) { # remove the wheel $heap -> { follow } -> DESTROY; delete $heap -> { follow }; } else { # Received $line, so inform the client about it $kernel -> post( 'IKC', 'post', "poe://$clientKernel/$clientSession/executeControl", [ $line ] ); } }, }, ); } #### #!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 );