tags 25549 patch quit npostavs@users.sourceforge.net writes: > > Tijs Mallaerts writes: > >> On my machine following steps seem to be a reproducible test case: >> >> - create a file "test-file.txt" with 20.000 identical lines with content "This is a line." >> - open eshell and insert the command: cat test-file.txt | grep line | wc >> >> This seems to return a different result every time it's run. > > Thanks, I can reproduce with this. The problem can be more easily reproduced (i.e., more often, and only 3000 lines) by cat test-file.txt | sleepy-cat | wc where sleepy-cat is #!/bin/sh while read line ; do echo "$line" sleep 0.000001 done The problem happens when one of the commands in the pipeline sends its output to Emacs quickly and the next command in the pipeline is slower. On receiving data from the first command in eshell-insertion-filter we call eshell-output-object to send it to the next command, but since sending might block, Emacs can run other process filters and sentinels instead. In this case, while sending a data chunk from cmd1 to cmd2, we actually end up reading all the data from cmd1 until it terminates and we call its sentinel. The sentinel closes the pipes and sends EOF to cmd2, but we still haven't sent the data from cmd1 to cmd2 yet. Closing the pipes in a timer, as in the patch below, seems to fix it for me.