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
In reply to Re: parent wants to capture output from a spawned child
by Zaxo
in thread parent wants to capture output from a spawned child
by perlknight
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |