Date: Thu, 16 Feb 2012 14:00:30 GMT From: Oliver Fromme <olli@lurza.secnetix.de> To: freebsd-bugs@FreeBSD.org Subject: Re: kern/154915: [libc] [patch] Force stdio output streams to line-buffered mode Message-ID: <201202161400.q1GE0Una090336@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/154915; it has been noted by GNATS. From: Oliver Fromme <olli@lurza.secnetix.de> To: bug-followup@FreeBSD.org, jeremie@le-hen.org Cc: Subject: Re: kern/154915: [libc] [patch] Force stdio output streams to line-buffered mode Date: Thu, 16 Feb 2012 14:49:50 +0100 (CET) I think introducing an environment variable for this purpose is a bad hack. I would advise against this. Many tools already have options for unbuffered or line-buffered output (for example cat -u), and there are also other ways to circumvent such problems. For example, the problem quoted in the PR can be solved like this, using the -u option of cat: $ iostat -x 1 | cat -un | grep ad1 or avoiding cat completely (also might be more efficient, saving one process and one pipe, though I haven't benchmarked this): $ iostat -x 1 | awk '{n+=1} /ad1/{print n, $0}' For certain other cases, I have the following alias in my ~/.zshrc that simulates a TTY environment for a tool so it is forced to use line-buffered output: alias intty='script -qt0 /dev/null' So I can write: $ intty sometool -args | grep ... However, the intty alias only works when it is the first command in a pipeline (this is a limitation of the "script" command). In the above example, the cat command is not the first, but a subshell can be used to work around this: $ intty sh -c 'iostat -x 1 | cat -n' | grep ad1 (It should work with any shell that supports aliases, not just zsh, of course.) I suggest closing this PR. Best regards Oliver
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201202161400.q1GE0Una090336>