As the documentation for IPC::Open2 tells you, the big problem with trying to interface with a program in this way, is that while you can be reasonably sure that your perl program isn't buffering (IPC::Open2 will turn on autoflush on the writer handle automatically) you probably can't control whether the program you are interfacing with is going to buffer due to the fact that it is reading from a pipe. If the program you are controlling does buffer the data (like sqlplus) then you have to close the writer to get it to process it's buffer. If the program you are controlling does not buffer (like bc) then it works just like you would expect. If you need to control something that is doing buffering, you would be better off with Expect, which can allocate a pseudo-tty and trick the program into thinking it is talking to a terminal rather than a pipe.


We're not surrounded, we're in a target-rich environment!

In reply to Re: can't read before closing the writer in open2 by jasonk
in thread can't read before closing the writer in open2 by karden

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.