Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Handling program output in real time

by pg (Canon)
on Nov 10, 2003 at 07:55 UTC ( [id://305822]=note: print w/replies, xml ) Need Help??


in reply to Handling program output in real time

Here is the fact behind what you observed: there are actually two types of buffering mechanism: line buffering and block buffering.

When you print to STDOUT:

  • The output is line buffered, if the target is a terminal; (This why you see output every 3 seconds on the screen, if you run your blackbox.pl on its own.)
  • otherwise (including pipe) the output is block buffered. (So in the pipe case, the problem is not your monitor program. But your blackbox.pl no longer outputs at the same pace, because of block buffering.)

By setting $| as Anonymous Monk indicated, you force the output to be flushed after each write.

  • Comment on Re: Handling program output in real time

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2024-04-18 21:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found