tee piping to head gives error message

Dave Korn dave.korn@artimi.com
Mon Feb 7 22:21:00 GMT 2005

> -----Original Message-----
> From: cygwin-owner On Behalf Of Buchbinder, Barry (NIH/NIAID)
> Sent: 07 February 2005 17:28

> As described in the Subject.  Though it seems that everything works OK; tee
> just gives and error message under some circumstances.
> /tmp> cat stafflist.htm | tee ttt | head > /dev/null
> tee: standard output: Broken pipe

> So the file that tee write looks good and the write error is 
> only to the pipe.

  That'll be because head closed the pipe, and tee was still trying to write
into it.

> So head seems to be passing on the number of lines that ones 
> asks it to pass on.

  Given that the purpose of head is to print the first few lines of a file, it
kind of makes sense to me that it would close the file after it's read them
rather than keeping the input file open and manually reading-and-discarding the
entire rest of it for no good reason.

  So I reckon this is as-expected and by-design behaviour.

> So it seems to be specific to piping from tee to head.

  It's just that tee notices when a write to stdout fails, whereas most
applications are more loosely coded and don't check.

> But the number of lines/bytes at which the error disappears 
> does not seem to be constant.

  Umm, no, .... it's equal to the number of lines in the source file.

> So it seems that when given enough lines/bytes, there is no 
> error message.

  If you ask head for less lines than are in the source file, it closes its
input (which is tee's output) before tee has written the entire file, and tee
complains.  OTOH if you ask head for >= the number of lines in the source file,
tee completes, and head notices that it has no more input and exits gracefully.

> Everything should be up to date.  

  Except perhaps your caffeine levels this morning ?

Can't think of a witty .sigline today....

Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

More information about the Cygwin mailing list