wind has asked for the wisdom of the Perl Monks concerning the following question:
# name: basicipc.pl # # Purpose: Receive the STDOUT from a secondary app in real time # and do some basic translation on it. End when the secondary # app ends. my $cmd = 'perl delayed.pl'; open(CMD, "$cmd |") or die "Can't open $cmd: $!"; while (<CMD>) { my ($num) = /(\d+)/; print $num % 2 ? 'odd: ' : 'even: '; print $_; } close(CMD);
Now the problem with the above code is that the open command in basicipc.pl appears to be blocking, as in it does not succeed until the delayed.pl script is finished.# name: delayme.pl # # Purpose: Simulate an external process sending delayed # output to STDOUT for input into a script. my $MAX = 5; # In Seconds; for (1..$MAX) { sleep 1; print "Step $_ of $MAX\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Basic IPC Example
by kyle (Abbot) on Jul 25, 2007 at 02:26 UTC | |
by wind (Priest) on Jul 25, 2007 at 02:45 UTC | |
by zentara (Cardinal) on Jul 25, 2007 at 12:04 UTC | |
Re: Basic IPC Example
by BrowserUk (Patriarch) on Jul 25, 2007 at 06:25 UTC |