[net.unix] tee command without buffering

kvancamp@ardc.arpa (LCWSL) (12/05/85)

Has anyone got a version of the tee command that doesn't buffer the I/O?
(When I tee my output from an interactive program, with one destination
being stdout, I'd like to see everything as it is printed.) Thanks for
your help.

			Ken Van Camp <kvancamp@pica-lca>

charliem@athena.UUCP (Charlie Mills) (12/10/85)

>Has anyone got a version of the tee command that doesn't buffer the I/O?

The standard solution under 4.2BSD is to use tail -f on the output
file.  (Don't use tee.)  Tail -f doesn't buffer its output between
sleeps.  You can kill or suspend the tail without disturbing the
process generating the data.  I don't know whether System V has tail or
if so whether there is a -f option or something analogous.

	-- Charlie Mills
..{ucbvax,decvax,uw-beaver,hplabs,ihnp4,allegra}!tektronix!athena!charliem

kvancamp@ardc.arpa (LCWSL) (12/10/85)

Thanks to all of you who responded to my question about stopping buffering
of the tee command (so I could see my output at the same time I echo it
to a file). A few suggestions I got were:

1.) Use script. This sounds like it would do the job, but my Masscomp system
doesn't have this.

2.) xxx | tee something | cat -u    where the -u should force it to be
unbuffered. This doesn't seem to work.

3.) Put /dev/null as one of the tee arguments, also to force buffering.
I interpreted this as:   xxx | tee /dev/null | tee something
This, too, doesn't seem to work.

The fourth reply I got was from someone who said that what I wanted is
impossible because the buffering is inherent in the system (i.e., it isn't
the fault of tee because tee already works on only one byte at a time).

Does anyone have any other suggestions? Do you know how I can get a copy
of script, without violating any copyright laws; or can someone at least
point me in the right direction on how to write one? Any help would be
appreciated. Please respond directly to me as I do not subscribe to the
group. Thanks in advance.

			Ken Van Camp <kvancamp@pica-lca.arpa>

gnu@l5.uucp (John Gilmore) (12/11/85)

In article <509@brl-tgr.ARPA>, kvancamp@ardc.arpa (LCWSL) writes:
> Thanks to all of you who responded to my question about stopping buffering
> of the tee command (so I could see my output at the same time I echo it
> to a file)...what I wanted is
> impossible because the buffering is inherent in the system (i.e., it isn't
> the fault of tee...

The problem is that a program whose output is a pipe will buffer
up a large block of stuff before it writes it to the pipe.  If the output
is to a terminal, it sends it out as soon as the program writes it.
This is done by the standard I/O library to improve performance.
Thus if you have xxx | tee file  the problem is in stdio in xxx; it's
not in "tee".  There's no particularly good solution.

chris@umcp-cs.UUCP (Chris Torek) (12/12/85)

In article <509@brl-tgr.ARPA> kvancamp@ardc.arpa (LCWSL) writes:

> The fourth reply I got was from someone who said that what I wanted
> [`stopping buffering of the tee command'] is impossible because
> the buffering is inherent in the system (i.e., it isn't the fault
> of tee because tee already works on only one byte at a time).

Close.  The problem is not in tee, but neither is it in the system:
It is in the command you are using on the left hand side of the
pipe.  Most standard I/O libraries automatically line buffer file
output if the file itself is a terminal, and block buffer the output
otherwise.  A careful program will use `fflush' at appropriate
points; indeed, I find that the `helpful' line buffering is
unnecessary and even problematical at times.

If a program behaves differently---aside of course from speed---when
its output is run through an unbuffered `cat'-like filter (e.g.,
`tee /dev/null'), it is not well written.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@mimsy.umd.edu