dvergin has asked for the wisdom of the Perl Monks concerning the following question:
Given some program that produces output over time, let's call it "blackbox.pl":
I had expected (and wanted) the following code to capture and print out that output as it occurred:#!/usr/bin/perl use warnings; use strict; for my $step (1..4) { sleep 3; print "Step $step\n"; }
But what it does (with or without the $|++) is wait until blackbox.pl finishes and then it prints out all the output at once.#!/usr/bin/perl use warnings; use strict; $|++; open PIPE1, "./blackbox.pl |"; while ( <PIPE1> ) { # ...Filter and munge $_ print $_; } close PIPE1;
What am I doing wrong? How can I capture and print the output of blackbox.pl as it occurs? (Needless to say, the real program will be doing some filtering and munging along the way.)
TIA, David
------------------------------------------------------------
"Perl is a mess
and that's good because the
problem space is also a mess." - Larry Wall
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Handling program output in real time
by pg (Canon) on Nov 10, 2003 at 07:55 UTC | |
Re: Handling program output in real time
by Anonymous Monk on Nov 10, 2003 at 06:31 UTC | |
by dvergin (Monsignor) on Nov 10, 2003 at 07:04 UTC | |
by Anonymous Monk on Nov 10, 2003 at 07:15 UTC | |
by dvergin (Monsignor) on Nov 10, 2003 at 07:37 UTC | |
by Anonymous Monk on Nov 10, 2003 at 08:25 UTC | |
by etcshadow (Priest) on Nov 10, 2003 at 16:15 UTC | |
Re: Handling program output in real time
by hmerrill (Friar) on Nov 10, 2003 at 14:29 UTC | |
by etcshadow (Priest) on Nov 10, 2003 at 19:56 UTC |
Back to
Seekers of Perl Wisdom