twotone has asked for the wisdom of the Perl Monks concerning the following question:
I am using chapter 16 from the Perl Cookbook to try to figure out how to pass information to another program, then get results back from that program. I am using two perl scripts test1.pl and test2.pl.
Eventually I will be communicating with a "someprogram.exe" written and compiled in fox pro by another programmer. For now, I'm using the two perl scripts to get it figured out. (both programs will be on the same machine)
So far, I can activate the test2.pl script and get info back from it, but I can't successfully send info from test1.pl to test2.pl.
Here are the scripts:
test1.pltest2.pl#!/usr/bin/perl -w #test1.pl use IPC::Open2; use IO::Handle; use strict; my $output = ''; my $program = 'test2.pl'; my ($infh,$outfh) = (IO::Handle->new, IO::Handle->new); open2($infh, $outfh, ($program)); print $outfh "The rain in Spain stays mainly on the plain.\n"; while (<$infh>) { $output .= $_; } close($outfh); close($infh); print $output; exit;
#!/usr/bin/perl -w #test2.pl use strict; my $input = ''; my $error = "We received nothing!"; while (my $line = <STDIN>) { $input .= $line; } if ($input ne '') { print "We received input:\n"; print $input; } else { print $error; } exit;
I run test1.pl and all I get back is "We received nothing!" from test2.pl.
Any ideas what I'm doing wrong?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: communicating with another program
by Perl Mouse (Chaplain) on Nov 30, 2005 at 10:00 UTC | |
by twotone (Beadle) on Dec 01, 2005 at 04:30 UTC | |
|
Re: communicating with another program
by Delusional (Beadle) on Nov 30, 2005 at 11:07 UTC | |
by twotone (Beadle) on Dec 01, 2005 at 04:25 UTC |