nodejs / nodejs/node

`for await (const c of process.stdin)` does not accept EOF in Windows

Đang mở
#61,397 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

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?
  1. Run node -e "for await (const c of process.stdin) console.log(c)"
  2. [f] [o] [o] [Enter]
  3. [Ctrl] + [Z] or [Ctrl] + [D] (= EOF)
  4. [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

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. 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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.