Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Printing to STDOUT buffered when invoking Perl within a bash-script using tee

by haukex (Archbishop)
on Dec 05, 2016 at 15:24 UTC ( [id://1177229]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1177229]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-04-24 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found