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
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.