On Mon, Nov 9, 2009 at 3:03 PM, John Mendenhall <j...@surfutopia.net> wrote:

>> The mystery to me is why the error message does not appear
>> when the pipe is run on a tty.  (I can duplicate your error easily).
>>
>> To me this looks like normal operation.  You seem to be getting
>> the output you want, right?
>
> Yup.  So, I guess I can just throw away the standard error, to
> clean it up a bit.  Definitely not a real issue.  Just a curiosity
> that I like solving.  I was just wondering why it runs differently
> in different environments.

Well, output in sort(3) is through a macro,
sort.h: if (!fwrite(ptr, size, n, f))                                   \
sort.h:          err(2, "fwrite");                                      \

There's no funny business with isatty().  It might have to do with
buffering, different buffer size in each case?  That's a shot in the
dark.  Timing?  I really don't know.  (But I am, like you, curious.)
I can't imagine the source for err(3) making a decision, so this
must be buried in stdio source for fwrite.  Maybe even in the shell
that set up the pipe in the first place.  Maybe in a system call...
Maybe in the lunar phase...   Anyway 2>/dev/null can work wonders
for this sort of thing.

Dave

Reply via email to