My immediate thought was to reach for Expect, which I use for managing process from Perl in other scripts. Seems like a bit of overkill just to merge STDOUT, but it does work, since (by default) the output of commands spawned by Expect goes to the script's STDOUT.

Here's a sample script, with debugging lines left in for flavor:

#!/usr/bin/perl -w use strict; use Expect; $Expect::Multiline_Matching = 0; my @todo = ("ls /etc", "ps axw", "du"); my @cmds; foreach my $cmd (@todo) { print "spawning $cmd\n"; push @cmds, Expect->spawn($cmd); die "Didn't spawn $cmd\n" unless $cmds[-1]; } print "cmds = @cmds\nExpecting...\n"; while (@cmds) { expect( 1, '-i', \@cmds, [ qr"^.*\n", sub {print "\n", shift, " did something\n"; exp_continue;} ], [ 'eof', sub { my $done = shift; print "$done is finished\n"; @cmds = grep {$_ != $done} @cmds; print "cmds = @cmds\n"; } ], ); } print "Everything finished\n";
The first pattern match is useless, it just adds some output to say which command was active. The second match is the only required one for your purpose. It deletes commands from the list as they finish, and recycles the expect call.

One benefit of going this route is that you could put in pattern matches for rsh error output and take special action, while ignoring most of the output.

Expect is nice for letting you take care of things that matter and ignore the bulk of a process's output.


In reply to Re: Multple Processes by TheoPetersen
in thread Multple Processes by ktelep

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.