(echo foo ; sleep 1) | pee cat echo cat cat

Outputs just one foo here.

I'm quite sure the issue is that 'echo' close the stream immediately, causing a 
SIGPIPE that kills the pee process.

The same problem happens when you want both head and tail of a large stream:

    $ seq 100000 | pee 'head -n1' 'tail -n1'
    1
    14139


Adding empty signal handler for SIGPIPE


    void handle_sig(int sig) {}

    /* ... */

           signal(SIGPIPE, handle_sig);

and simply ignoring the write error in pee.c fixes the head/tail case.

A workaround is
    
   $ seq 100000 | pee 'head -n1; cat >/dev/null' 'tail -n1'

I'm sure there are cases where one wants the SIGPIPE to abort the rest of 
pipes, but there should at least be an option to ignore it.

Reply via email to