Why does this simple command fails using emacs shell (eshell)?
cat file.txt | wc
I have a file with 10241 lines. Each line has less than 50 characters. Around 90% of the times I launch this command, it gives the wrong result, namely line count. Nonetheless, no error messages are given.
Looks like broken pipe is a very common topic, but I haven't found any reasonable explanation. Also, no one proposes any workarounds. How can I get this simple command working reliably?
Of course, I could've just run wc file.txt
. But I'm looking for a more general solution in which any tool would work fine piped cat: cat file.txt | any_tool_here
.
Details
I'm using CentOS 5. This issue appears when using eshell (emacs shell). I'm using GNU Emacs 24.5.2.
Experiments
Samples of results using cat file.txt | wc
(expected: first column to be always 10241).
- 8568 25706 110571
- 9837 29513 126947
- 5395 16187 69615
- 9202 27608 118757
- 7299 21899 94199
- 9837 29513 126947
Sample of results using wc file.txt
:
- 10241 30723 132156
- 10241 30723 132156
- 10241 30723 132156
- 10241 30723 132156
- 10241 30723 132156
- 10241 30723 132156
The cat command itself (when executed alone) is working properly. I validated it with the following command (a few times): cat file.txt > file2.txt
. Then, I diff'd both files and they are identical.
cat
, I've never seen what you describe (and I just tested it with a file with 10240 lines of 50 characters each; it ran 1000 times with no error). Are you running this while another process is writing tofile.txt
? What operating system are you using?wc file.txt
always work as expected?