I don't know if the following code is the correct solution
for your problem because it does not handle any (interactive)
user input (besides it's just a quick hack -- without error handling).
Short Description:
------------------
- open a pipe to each given process (@ARGV) 8|
- poll each pipe for new data (optionally print data)
- finished if each filehandle returns eof
#!/usr/local/bin/perl -w
use strict;
use IO::File;
my $count = 0;
my @fdesc = ();
my %fdname;
# create pipes
foreach my $prog (@ARGV) {
my $fh = IO::File->new("$prog |");
push(@fdesc, $fh);
$fdname{$fh} = $prog;
}
# listen
my $notDone=0;
do {
$notDone=0;
foreach my $fh (@fdesc) {
if (!$fh->eof()) {
$notDone=1;
print "<",$fdname{$fh},">: ",$fh->getline();
}
}
} while ($notDone);
example usage: combineLog.pl ls "ps auxw" "du -sk ~*" > comb.log 2>&1
MP |