tags:

views:

75

answers:

2

I have an executable which reads from STDIN and output goes to STDOUT.

I need a Perl script which will fork this executable as a child and write to STDIN of that child process and read from the STDOUT.

This is required for Windows. Any ideas or suggestions?

+1  A: 

The prescribed solution is the IPC::Open2 module, but the code below may hang on Windows.

#! /usr/bin/perl

use warnings;
use strict;

use IPC::Open2;

my $pid = open2 my $out, my $in, "./myfilter.exe";
die "$0: open2: $!" unless defined $pid;

print $in "$_\n" for qw/ foo bar baz /;
close $in or warn "$0: close: $!";

while (<$out>) {
  chomp;
  print "Parent: [$_]\n";
}

close $out or warn "$0: close: $!";
Greg Bacon
It seems there is no clean solution for Windows.
Avinash
+3  A: 

perlfaq8 How can I open a pipe both to and from a command?

daxim
`perldoc -q` should be advertised more.
Dummy00001