in reply to Re: Best practice ipc and Log::Log4perl
in thread Best practice ipc and Log::Log4perl
What I want:
read unbuffered from a child process ( long running process ).
capture childprocess stderr & stdout separately
write the childprocess stdout and stderr stream to a logfile and tag lines with a <timestamp> and a tag <INFO> or <ERROR> depending on the source stream.
IPC::Run3 almost does what I need.
#!/usr/bin/perl # timestamp.pl $|++; while(time - $^T<10){ select undef,undef,undef, 0.1; if ( rand()<0.5) { print STDERR time(), " warn\n"; } else { print time(), " info\n"; } } __END__
use IPC::Run3 qw(run3); my @cmd = ('perl', 'timestamp.pl'); run3 \@cmd, undef, \&out, \&err; sub out { print time(), " out: $_\n"; } sub err { print time(), " err: $_\n"; } __END__ # The problem is that run3 buffers the output. 1215162770 out: 1215162760 info 1215162770 out: 1215162760 info 1215162770 out: 1215162761 info 1215162770 out: 1215162761 info 1215162770 out: 1215162761 info 1215162770 out: 1215162761 info 1215162770 out: 1215162762 info 1215162770 out: 1215162762 info 1215162770 out: 1215162762 info 1215162770 out: 1215162763 info
print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Best practice ipc and Log::Log4perl
by starbolin (Hermit) on Jul 05, 2008 at 03:00 UTC | |
by codeacrobat (Chaplain) on Jul 05, 2008 at 08:41 UTC | |
by jointwork (Initiate) on Apr 25, 2009 at 20:04 UTC |
In Section
Seekers of Perl Wisdom