The problem is this:
chomp(@outlines = <CHILD_OUT>); close (CHILD_OUT); chomp(@errlines = <CHILD_ERR>); close (CHILD_ERR);
You are making the assumption (maybe you don't realize that you are) that your subprocess is working in a very 1, 2, 3 fashion. That is, it reads STDIN (completely), and then it writes STDOUT (completely) and then it is done (never writing STDERR... except of course, unless it explicitly closes its STDOUT before doing its writes to STDERR, which I'm sure it doesn't).

If it writes anything to STDERR, then everything will hang. The reason is that the two processes are deadlocked. The first is waiting on the second to write STDOUT, and the second is waiting on the first to read STDERR. One thing you may have missed in the IPC::open3 documentation is the fact that these pipes are synchronized between the parent and child. If the child is trying to write STDERR, then the parent must be reading the child's STDERR. If not, then the child will wait until the parent is ready to read. Likewise, if the parent is reading the child's STDOUT, then it will wait until the child writes STDOUT.

So how do you deal with this? You either do it the hard way, which is to learn about IO::Select and non-blocking I/O. (That is, instead of having the parent say "read the child's STDOUT", say "try to read the child's STDOUT, if the child is trying to write STDOUT, else try to read the child's STDERR.... etc"). Or, you do it the easy, somewhat hackish way, which is to either ignore STDERR or lump it together with STDOUT. You can look into IPC::open2 for that tack. Of course, this all, also, relies on the assumption that the subprocess will do all of its reading before it does any of its writing.


------------
:Wq
Not an editor command: Wq

In reply to Re: IPC::Open3 & closed STDOUT by etcshadow
in thread IPC::Open3 & closed STDOUT by lgauthie

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.