in reply to parent wants to capture output from a spawned child
If you fork by way of magical open the kids can print their messages and you can read them on the filehandle:
IO:Select would improve this. You might also look at Parallel::ForkManager.#!/usr/bin/perl -w use strict; my %kids = (); my @msgs = (); $SIG{CHLD} = q/IGNORE/; for ( 'a', 'b', 3) { my ( $pid, $fh); defined($pid = open $fh, "-|") or warn $! and last; if ($pid) { # be parental $kids{$pid} = $fh; next; } else { kid_code($_); } } push @msgs, <$_> for values %kids; print @msgs; sub kid_code { # do childish things, then (goes to $fh in parent) print "$_[0]. Your Message Here$/"; exit(0); }
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: parent wants to capture output from a spawned child
by perlknight (Pilgrim) on Nov 26, 2001 at 01:04 UTC | |
by Zaxo (Archbishop) on Nov 26, 2001 at 02:02 UTC |