http://www.perlmonks.org?node_id=628603

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

Greetings Monks, I'm attempting to create a simple example for testing interaction with a secondary application. I have no experience with IPC yet, but my hope is to make code that is functional on both linux and ActivePerl. Here are the basic scripts that I'm starting from.
# 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);
# 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"; }
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.

Now, if I wasn't doing any translation of the output, I could simply take advantage of the advice in perlipc for Background Processes, as that method lets the secondary process share the same STDOUT and STDIN as the parent. But my goal is to start off being able to translate the output, and then move on to bi-directional interaction.

I have access to most of the major perl books. However, there appear to be so many tools that could be used for this purpose, that I'm finding it difficult on deciding where to start. Especially when trying to maintain code that would support both Linux and Windows.

Regards,
- Miller