in reply to Collecting STDOUT from childeren (and subchilderen) via pipe()

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