To be frank, the question is a little bit vague, at least to me. Hopefully I guessed your requirement correctly, and my two samples cover some of your needs.

Two tips:

The first sample shows how to make one parent talk to multiple children thru the same pipe:

use IO::Handle; use IO::Select; use strict; use warnings; $| ++; pipe(PARENT_RDR, CHILD_WTR); if (fork()) { if (fork()) { close CHILD_WTR; while (my $line = <PARENT_RDR>) { print "parent got $line"; } } else { close PARENT_RDR; for (100..110) { print CHILD_WTR "$_\n"; } } } else { close PARENT_RDR; for (0..10) { print CHILD_WTR "$_\n"; } }

This prints:

parent got 0 parent got 1 parent got 2 parent got 3 parent got 4 parent got 5 parent got 6 parent got 7 parent got 8 parent got 9 parent got 10 parent got 100 parent got 101 parent got 102 parent got 103 parent got 104 parent got 105 parent got 106 parent got 107 parent got 108 parent got 109 parent got 110

The second sample shows how to make pipes chained, so that grandparent can talk to grandchild:

use IO::Handle; use strict; use warnings; $| ++; pipe(GRANDPARENT_RDR, PARENT_WTR); if (fork()) { close PARENT_WTR; while (my $line = <GRANDPARENT_RDR>) { print "grand parent got $line"; } } else { close GRANDPARENT_RDR; pipe(PARENT_RDR, CHILD_WTR); if (fork()) { close CHILD_WTR; while (my $line = <PARENT_RDR>) { print "parent got $line"; print PARENT_WTR $line; } } else { close PARENT_RDR; for (0..10) { print CHILD_WTR "$_\n"; } } }

This prints:

parent got 0 parent got 1 parent got 2 parent got 3 parent got 4 parent got 5 parent got 6 parent got 7 parent got 8 parent got 9 parent got 10 grand parent got 0 grand parent got 1 grand parent got 2 grand parent got 3 grand parent got 4 grand parent got 5 grand parent got 6 grand parent got 7 grand parent got 8 grand parent got 9 grand parent got 10

In reply to Re: Collecting STDOUT from childeren (and subchilderen) via pipe() by pg
in thread Collecting STDOUT from childeren (and subchilderen) via pipe() by johnc909

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.