From owner-freebsd-hackers@FreeBSD.ORG Sun Jul 5 12:20:59 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 8CB2D106564A for ; Sun, 5 Jul 2009 12:20:59 +0000 (UTC) (envelope-from a_best01@uni-muenster.de) Received: from zivm-out3.uni-muenster.de (ZIVM-OUT3.UNI-MUENSTER.DE [128.176.192.18]) by mx1.freebsd.org (Postfix) with ESMTP id 2217D8FC0C for ; Sun, 5 Jul 2009 12:20:58 +0000 (UTC) (envelope-from a_best01@uni-muenster.de) X-IronPort-AV: E=Sophos;i="4.42,351,1243807200"; d="scan'208";a="7609342" Received: from zivmaildisp2.uni-muenster.de (HELO ZIVMAILUSER03.UNI-MUENSTER.DE) ([128.176.188.143]) by zivm-relay3.uni-muenster.de with ESMTP; 05 Jul 2009 14:20:57 +0200 Received: by ZIVMAILUSER03.UNI-MUENSTER.DE (Postfix, from userid 149459) id 9FA521B0751; Sun, 5 Jul 2009 14:20:57 +0200 (CEST) Date: Sun, 05 Jul 2009 14:20:57 +0200 (CEST) From: Alexander Best Sender: Organization: Westfaelische Wilhelms-Universitaet Muenster To: Jilles Tjoelker Message-ID: In-Reply-To: <20090705120514.GA45921@stack.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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:20:59 -0000 thanks. i remembered fprintf being buffered, but i always thought \r would also empty the buffer. now that explains everything. ;-) alex Jilles Tjoelker schrieb am 2009-07-05: > 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.