Hi,

I have some problems with bidirectional communication with an .exe application using perl.

Here is what I am trying to do :
I have a c++ console application which asks for a list of values un the standard input, multiply all the elements of the list by a value and print the new list on the standard output. (This is only an example to get me started actually)

Then, I am trying to run the application from a perl script, write to the application some values using the script, and read the new values returned on the standard output from the application.

Here is my perl code for now :

#!/usr/bin/perl use IPC::Open2; my $toExec = "testfigure.exe"; my @xList = (1,2,3,4,5); my $ret; local(*WR, *RD); my $pid = open2(\*RD, \*WR, $toExec); my $length = @xList; print WR "$length\n"; foreach my $xVal (@xList){ print WR "$xVal\n"; } print WR "3\n"; while($ret = <RD>){ print; } waitpid($pid,0);

And here is the problem I'm running into :
I cannot read from the application. The part while($ret = <RD>) does not work, I'm always getting an empty $ret (no reading is done). Though, I can write to the application and it does print @xList multiply by 3 on the screen. I have looked all the examples I could find on the web, and read all the perlipc manpage but there is nothing about such a problem. I am using Windows 2000 professional (maybe it is a known bug).

If anyone has any idea why this code does not work properly, I would really appreciate the help !

Thanks to you

2006-07-23 Retitled by g0n, as per Monastery guidelines
Original title: 'Bidirectionnal Communication with Another Process'


In reply to Bidirectional Communication with Another Process by duc

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.