Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 5 Jul 2009 14:05:14 +0200
From:      Jilles Tjoelker <jilles@stack.nl>
To:        Alexander Best <alexbestms@math.uni-muenster.de>
Cc:        freebsd-hackers@FreeBSD.org
Subject:   Re: carriage return with stdout and stderr
Message-ID:  <20090705120514.GA45921@stack.nl>
In-Reply-To: <permail-2009070511420180e26a0b0000695f-a_best01@message-id.uni-muenster.de>
References:  <permail-2009070511420180e26a0b0000695f-a_best01@message-id.uni-muenster.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Jul 05, 2009 at 01:42:01PM +0200, Alexander Best wrote:
> i'm running something similar to this pseudo-code in an app of mine:

> for (i=0 ....)
>     fprintf(stdout,"TEXT %d\r", int);

> what's really strange is that if i print to stdout the output isn't very
> clean. the cursor jumps randomly within the output (being 1 line). if i print
> to stderr however the output looks really nice. the cursor says right at the
> front of the output all the time. just like in burncd e.g.

> what's causing this? because i'd rather print to stdout.

If you are writing to a terminal, stdout is line-buffered. This means
that output is flushed when the buffer is full or a '\n' is written. A
'\r' is not good enough. You can force a write using fflush(stdout).

stderr is always unbuffered, so everything is written immediately.

-- 
Jilles Tjoelker



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090705120514.GA45921>