Good luck with that. :)

In the general case, you risk deadlock. To avoid deadlock, you run into the areas where Perl 5 tends to disappoint: threads or async I/O.

Even if you do something either problematically complicated or "less elegant" (writing either the input or the output to a temporary file) in order to avoid deadlock, then you run into the decades-old problem of libc not flushing output the same. (It is a shame that in those decades, libc has still not been taught to flush "like to a TTY" if some environment variable is set.)

To solve that problem, you either have to have the ability to modify the code being run in the subprocess or you have to deal with pseudo ttys.

I usually find that the easiest way to deal with pseudo ttys is to ssh to localhost.

Of course, this is why "expect" was built. But getting a working Perl version of "expect" can be a bit of a challenge (at least the last time I saw somebody try).

- tye        


In reply to Re: How to print to STDIN of a cmd and read it's STDOUT (ouch) by tye
in thread How to print to STDIN of a cmd and read it's STDOUT by mhearse

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.