[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug in 'tee' version 2.0

From: Bob Proulx
Subject: Re: bug in 'tee' version 2.0
Date: Tue, 27 Feb 2001 21:32:48 -0700


> I tried to use 'tee' to log all inputs to some program:
> tee x.log|someprogram
> But when 'someprogram' terminates, 'tee' still keeps on waiting for
> input. It apparently ignores the fact that the pipe is no more there.

This behavior would be hard to avoid.  Have you tried the following?
I believe it should behave the same.

  cat | someprogram

The problem is that any program writing into the pipe won't know the
program reading from the pipe is gone until it tries to write.  At
that time it will get a SIGPIPE signal.  But it doesn't have anything
to write into the pipe until you give the first program some input.
Therefore it must wait for input.

In your example the tee program is reading from standard input and is
waiting for you to type something into it before it can write that to
standard output.  By the way, the tee program does not know that
standard output is being piped to another program.  Your command shell
set that up and then launched both programs.  All the programs know is
that they are reading from standard input and writing to standard

In general the normal case of pipe filters is to have the first
program in the pipe terminate first, such as at the end of a file it
was reading.  That causes the second program in the pipeline to see
the end of input and terminate.  The end-of-file, such as it is, gets
passed on from left to right.  You are asking for it to go backwards
from right to left which does not work the same.  The OS handles this
by sending a SIGPIPE signal asynchronously around the outside of the
pipeline if you try writing to a dead pipe.

The "script" command was developed to help with some of the problem of
input logging.  Read the man page for script and see if that will work
for you.  [Assuming you are running bash the SHLVL (echo $SHLVL)
variable will help keep track of how many command shells you have
stacked and might also be useful to you.]


reply via email to

[Prev in Thread] Current Thread [Next in Thread]