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.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;
test2.pl
#!/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?

WinXP, ActiveState Perl 5.6.1

In reply to communicating with another program by twotone

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.