Here's a sample script, with debugging lines left in for flavor:
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.#!/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";
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |