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

Issac Goldstand margol at beamartyr.net
Wed Nov 18 01:22:23 PST 2009


Offer Kaye wrote:
> On Tue, Nov 17, 2009 at 1:47 PM, Gabor Szabo wrote:
>   
>> Something like this ?
>>
>> open my $ph, "$cmd |" or die;
>> while (my $line = <$ph>) {
>>     $line =~ s/\n/<br>/gs;
>>     print $line
>> }
>>
>>     
>
> Looks right to me, except I think Issac will need to set autoflush,
> e.g. using "++$| ;" at the beginning of his script, to get output
> immediately as he asked for.
>
>   
That I already did.  I was hoping for perl to push the buffer through,
though.  My initial worry was that the script wouldn't differentiate
between "no more output yet" and "no more output, the command is done"
if I created a tight while loop.

  Yitzchak


More information about the Perl mailing list