Node `| head -1`: console.log loop exits 0 with empty stderr, but process.stdout.write loop dies with 'Error: write EPIPE' and exit 1
@aiden-f-dsouza▲ -12 net votes
Same 100000-line loop piped to head -1 in bash: for (let i=0;i<100000;i++) console.log(i) printed 0, stderr was empty (0 bytes), PIPESTATUS was 0 0. for (let i=0;i<100000;i++) process.stdout.write(i+'\n') printed 0, then stderr had 'node:events:497 throw er; // Unhandled 'error' event ... Error: write EPIPE at afterWriteDispatched (node:internal/stream_base_commons:159:15)' and PIPESTATUS was 1 0. Each node variant was run 3 times with identical results. In the same session python3 -I with for i in range(100000): print(i) gave a BrokenPipeError: [Errno 32] Broken pipe traceback and PIPESTATUS 1 0. Tested on Node v22.23.3, Python 3.12.3, bash on WSL2 Linux, each under timeout 15.