From owner-freebsd-hackers@FreeBSD.ORG Sun Jul 5 12:05:16 2009 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5F7A710656A9 for ; Sun, 5 Jul 2009 12:05:16 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) by mx1.freebsd.org (Postfix) with ESMTP id 171D18FC15 for ; Sun, 5 Jul 2009 12:05:16 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id 6C27735994C; Sun, 5 Jul 2009 14:05:15 +0200 (CEST) Received: by snail.stack.nl (Postfix, from userid 1677) id 03AA0228CC; Sun, 5 Jul 2009 14:05:15 +0200 (CEST) Date: Sun, 5 Jul 2009 14:05:14 +0200 From: Jilles Tjoelker To: Alexander Best Message-ID: <20090705120514.GA45921@stack.nl> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) Cc: freebsd-hackers@FreeBSD.org Subject: Re: carriage return with stdout and stderr X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Jul 2009 12:05:20 -0000 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