in reply to Re^2: Printing to STDOUT buffered when invoking Perl within a bash-script using tee
in thread Printing to STDOUT buffered when invoking Perl within a bash-script using tee

Hi TJCooper,

the Perl script is NOT buffered when ran as a standalone script

A described in the article I linked to, Perl decides whether STDOUT should be line or block buffered depending on whether it is connected to a terminal or not. For example, you should notice a difference in the behavior of the following: the middle one delays its output until the end due to the buffering.

$ perl -le 'for (0..10) { print; sleep 1 }' $ perl -le 'for (0..10) { print; sleep 1 }' | tee /tmp/foo $ perl -le '$|=1; for (0..10) { print; sleep 1 }' | tee /tmp/foo
I have tried this

In the following bash script, if I remove the $|=1;, it displays the undesired behavior you describe; with the autoflush turned on it shows the expected "live" view.

#!/bin/bash exec > >(tee "/tmp/foo") perl -le '$|=1; for (0..10) { print; sleep 1 }'

So if you've tried $|=1; and are still getting the undesired behavior, perhaps you could show a Short, Self Contained, Correct (Compatible) Example for us to reproduce the problem.

... after your update to the node while I was typing my reply:

I had tried using that magic-variable and it did not work...but now it does.

Please see How do I change/delete my post?, especially "It is uncool to update a node in a way that renders replies confusing or meaningless".

Regards,
-- Hauke D

Update: Referenced article.