From owner-freebsd-hackers@FreeBSD.ORG Mon May 26 17:59:50 2008 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 E5C24106566B for ; Mon, 26 May 2008 17:59:50 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (unknown [IPv6:2a01:170:102f::2]) by mx1.freebsd.org (Postfix) with ESMTP id 576A38FC25 for ; Mon, 26 May 2008 17:59:50 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (localhost [127.0.0.1]) by lurza.secnetix.de (8.14.1/8.14.1) with ESMTP id m4QHxm6j091705; Mon, 26 May 2008 19:59:48 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.14.1/8.14.1/Submit) id m4QHxmpi091704; Mon, 26 May 2008 19:59:48 +0200 (CEST) (envelope-from olli) Date: Mon, 26 May 2008 19:59:48 +0200 (CEST) Message-Id: <200805261759.m4QHxmpi091704@lurza.secnetix.de> From: Oliver Fromme To: freebsd-hackers@FreeBSD.ORG, mathieu.prevot@gmail.com In-Reply-To: <3e473cc60805260626k2469143ay9b0d52ea4044938b@mail.gmail.com> X-Newsgroups: list.freebsd-hackers User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (FreeBSD/6.2-STABLE-20070808 (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Mon, 26 May 2008 19:59:48 +0200 (CEST) Cc: Subject: Re: flush file descriptor in a sh script while passing through a pipe X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-hackers@FreeBSD.ORG, mathieu.prevot@gmail.com List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 May 2008 17:59:51 -0000 Mathieu Prevot wrote: > Let's be an example. With 1) I have a progress bar that is updated > regularly but with 2) I have to wait for the end of the download (the > next \n character ?) ... > > 1) > wget http://tinyurl.com/5ztnb2 > > 2) > wget http://tinyurl.com/5ztnb2 --progress=bar:force 2>&1 | sed > '/^Location/d;/^HTTP/d;/^--/d' > > I would like the progress bar to be updated through sed ... how can I > flush the file descriptor from sh or with a tiny command/signal ? There are two problems with that. The first problem is the fact that wget's output is fully buffered when output is a pipe (not a tty). Some programs have an option for unbuffered or line-buffered output (e.g. tcpdump -l), but unfortunately wget does not. In fact most programs don't have such an option. There's a little trick that "emulates" a tty environment for a process so it thinks that its standard output is a tty, so output will be unbuffered: Simply run it inside script(1). I've needed that for myself occasionally so I've made a small alias for this: alias intty='script -qt0 /dev/null