in reply to logging STDOUT of multiple scripts
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
example usage: combineLog.pl ls "ps auxw" "du -sk ~*" > comb.log 2>&1#!/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);
MP
|
|---|