That's a complex entity, rather beyond the scope of a "quick example". There are also some ambiguities in your description.
If processing is already done, they simply receive the output. If processing is not done, yet, they see the same (following) output of the process.
What if a read request is received for a process that has already started and produced half it's output? Does the new listener get everything that has already been sent to the file and any other listeners, or just that output the process produces after the request is received?
Anyway, here's how to use a thread to spawn a command and 'tee' it's output to a file, and retain a copy in memmory for your main thread to process at it convenience whilst also getting on with anything else it needs to do (like communicating with clients and monitoring queues):
#! perl -slw use strict; use threads qw[ yield async ]; use threads::shared; my( $cmd, $file ) = @ARGV; my $done : shared = 0; my @lines : shared; async { my $pid = open my $CMD, "$cmd |" or die "$cmd : $!"; open my $fh, '>', $file or die "$file : $!"; while( <$CMD> ) { chomp; print $fh $_; ## output to the file push @lines, $_; ## and push it to a shared array } $done = 1; }->detach; my $n = 0; while( !$done ) { if( @lines ) { ## lines to be processed print pop @lines; ## process them } else { ## Else nothing to do but wait. yield; } }
Whether that would work in conjunction with POE I'm not sure.
Personally, I would write the whole thing using threads, but that's rather more than your OP asked for, and would take a fair amount of effort.
In reply to Re^3: POE and Win32::Process control
by BrowserUk
in thread POE and Win32::Process control
by m-rau
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |