Since you need to send and receive data from the Java process, you need two-way communication. That's what IPC::Open2
is designed to do. This allows you to create a dedicated pipe that renders STDIN
/STDOUT
unnecessary:
use IPC::Open2;
my $pid = open2( \*from_jar, \*to_jar, $command )
or die "Could not open 2-way pipe: $!";
print to_jar, "Here is input\n"; # Pass in data
my $result = <from_jar>; # Retrieve results
Also consider IPC::Open3
to handle errors as well.