`for await (const c of process.stdin)` does not accept EOF in Windows
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.3k
- Merge trung bình
- 4 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 283
Mô tả
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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện vấn đề trên Windows với lệnh được báo cáo node -e "for await (const c of process.stdin) ..." và lần theo entry point của phép lặp bất đồng bộ của process.stdin. Công việc được xem là hoàn tất khi Ctrl+Z hoặc Ctrl+D được nhận diện là EOF, vòng lặp kết thúc và hành vi này được bao phủ bởi một bài kiểm thử hồi quy trên Windows.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, node.js
- Lĩnh vực
- cli, operating-systems
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 48/100