`for await (const c of process.stdin)` does not accept EOF in Windows
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 122k
- Forks
- 37.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 283
Description
Version
v24.13.0
Platform
Microsoft Windows NT 10.0.26200.0 x64
Subsystem
No response
What steps will reproduce the bug?
- Run
node -e "for await (const c of process.stdin) console.log(c)" - [f] [o] [o] [Enter]
- [Ctrl] + [Z] or [Ctrl] + [D] (= EOF)
- [Enter]
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
In Ubuntu and Alma Node successfully stop reading by Ctrl + D:
$ node -e "for await (const c of process.stdin) console.log(c)"
foo
<Buffer 66 6f 6f 0a>
What do you see instead?
Node will never stop reading in spite of [Ctrl] + [Z] or [Ctrl] + [D]:
PS> node -e "for await (const c of process.stdin) console.log(c)"
foo
<Buffer 66 6f 6f 0d 0a>
^Z
<Buffer 1a 0d 0a>
^D
<Buffer 04 0d 0a>
I had to end up with killing the process by Ctrl + C.
Additional information
I usually use Proto to manage Node versions, but it was able to be reproduced in the portable version in the official zipball:
PS> .\Downloads\node-v24.13.0-win-x64\node -e "for await (const c of process.stdin) console.log(c)"
foo
<Buffer 66 6f 6f 0d 0a>
^Z
<Buffer 1a 0d 0a>
^D
<Buffer 04 0d 0a>
PS> echo $?
False
(ended up with Ctrl + C)
Workaround: insert if ((c[0] === 4 || c[0] === 0x1a) && c.length === 1 + EOL.length && c.toString("latin1", c.length - EOL.length) === EOL) break; (import { EOL } from "node:os")
If this bug did not exist, you would be able to retrieve the entire multiline text from stdin by (await Array.fromAsync(process.stdin)).join("") in all platforms.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the reported node -e "for await (const c of process.stdin) ..." command on Windows and trace the process.stdin async-iteration entry point. Done means Ctrl+Z or Ctrl+D is recognized as EOF, the loop terminates, and the behavior is covered by a Windows regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100