I think you are reading too soon from your child process and the socket isn't readable resp. doesn't have output on it yet:

while ( my @ready = $select->can_read()) { ... };

A quick fix could be to sleep some time before first trying to read output of the child:

sleep 2; # give time to child process while ( my @ready = $select->can_read()) { ... };

A better fix would most likely be to split up output reading and child checking into two parts, but checking if a child is still running/alive is hard to do unless you know on what OS you will be running:

my @children = get_child_pids(); # fake while (@children) { while ( my @ready = $select->can_read()) { ... }; @children = get_child_pids(); # fake sleep 5; # let's see if the remaining children will produce output };

I'm punting on the check for alive children. The easiest way to check for alive children would be if you're under Linux to check for -d /proc/$child_pid, and maybe there is some way in Perl to get at the list of PIDs associated with your current PID, but I don't know it at the moment. Somebody else will chime in with that, I hope. CPAN might know too.


In reply to Re: ipc::open3 start process by Corion
in thread ipc::open3 start process by Murcia

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.