[Israel.pm] printing the output of `command` with immediate flush

Gabor Szabo szabgab at gmail.com
Tue Nov 17 03:47:20 PST 2009


On Tue, Nov 17, 2009 at 1:33 PM, Issac Goldstand <margol at beamartyr.net> wrote:
> I currently have an external command which I run in my script through
> backtics  It takes several minutes to run to completion.
>
> I'd like to print the output immediately, with an added bonus if I can
> do s/\n/<br>/gs on it on-the-fly.
>
> Any good ideas?

Something like this ?

open my $ph, "$cmd |" or die;
while (my $line = <$ph>) {
     $line =~ s/\n/<br>/gs;
     print $line
}


Gabor


More information about the Perl mailing list