I'm writing a perl program that captures the output of another program, and I noticed that in a while <FILEHANDLE>
loop (so $_
contains the line read), the following occurs:
open XIN, "-|", "test_xsr"; # not getting in real time! FIX
while (<XIN>) {
print ".";
}
prints
....
after the program finishes while
open XIN, "-|", "test_xsr"; # not getting in real time! FIX
while (<XIN>) {
print $_;
}
prints
1
2
3
done
in real time while the program runs. (While I'm testing, the program always produces that output.)
Why does this inconsistency occur?
Is it possible to process output in real time without print
ing$_
?