From owner-freebsd-hackers@FreeBSD.ORG Sun Aug 29 21:00:45 2010 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 6FA5E1065670; Sun, 29 Aug 2010 21:00:45 +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 383058FC1B; Sun, 29 Aug 2010 21:00:45 +0000 (UTC) Received: from turtle.stack.nl (turtle.stack.nl [IPv6:2001:610:1108:5010::132]) by mx1.stack.nl (Postfix) with ESMTP id A1C1F35A884; Sun, 29 Aug 2010 23:00:44 +0200 (CEST) Received: by turtle.stack.nl (Postfix, from userid 1677) id 8CB4A172CC; Sun, 29 Aug 2010 23:00:44 +0200 (CEST) Date: Sun, 29 Aug 2010 23:00:44 +0200 From: Jilles Tjoelker To: Anonymous Message-ID: <20100829210044.GB60715@stack.nl> References: <20100828141625.GA69240@freebsd.org> <86aao694tm.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <86aao694tm.fsf@gmail.com> User-Agent: Mutt/1.5.20 (2009-06-14) Cc: Alexander Best , freebsd-hackers@freebsd.org Subject: Re: tiny patch to prevent head from closing pipes 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, 29 Aug 2010 21:00:45 -0000 On Sat, Aug 28, 2010 at 06:42:29PM +0400, Anonymous wrote: > Alexander Best writes: > > i just had subversion complain about a broken pipe while piping its > > output through awk straight to head [1]. i decided to add a switch > > to head which will tell it to never close a pipe unless the input > > has stopped [2]. > You can do same with sh(1), e.g. > $ svn log | (IFS=; while read li; do [ $((i+=1)) -le 10 ] && echo "$li"; done) > versus > $ svn log | (IFS=; while read li && [ $((i+=1)) -le 10 ]; do echo "$li"; done) > ... > svn: Write error: Broken pipe Even easier (and avoiding mangling through read) is svn log | { head; cat >/dev/null; } Beware that the cat command will not necessarily get all of the input. head may buffer reads and it is unable to push the extra data back onto the pipe. > But I think subversion should I think Subversion should not print an error message for broken pipe on its stdout. > > there's probably a much more efficient way of discarding the input > > without closing the pipe unless the input ceased. it's just a 5 > > minute hack in order to see if people find the idea useful or not. > > ;) > Can you give an example of usefulness that does not involve subversion? -- Jilles Tjoelker