Re: Glib::IO watcher unbuffered?

On Fri, Jan 19, 2007 at 06:15:21AM -0500, zentara wrote:
On Fri, 19 Jan 2007 09:24:53 +0100
"Philipp E. Letschert" <phil uni-koblenz de> wrote:

I would like to have unbuffered output processing from an external command
(command prints a line, sleeps, prints a line, sleeps ...):

   else {
       my $line = <$pipe>;

I tried to have $line processed without delay (autoflush all handles
everywhere...), but the watcher only prints bunches of lines after some longer
Why does the buffering happen and how to turn it off?

I think your problem is that <> blocks until it hits an EOF, but your
pipe never sends it.  It's a common problem with running top thru
a pipe. Try using sysread:

with sysread I had the same effect, but thanks for the hint - I tried
the following shell script as an replacement for the command:

while true; do
  echo "cmd output: $date"
  sleep 1;

and it worked - good to know there is no error in my code.

When run in a terminal the output of the command behaves just the same as the
above skript (with proper timing and new lines inserted) but obviously there is
a difference. I will ask where this is more on-topic...

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]