nodejs / nodejs/node

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

Aperta
#61,397 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo il problema su Windows con il comando indicato node -e "for await (const c of process.stdin) ..." e traccia il punto di ingresso dell’iterazione asincrona di process.stdin. Il lavoro è completato quando Ctrl+Z o Ctrl+D viene riconosciuto come EOF, il ciclo termina e il comportamento è coperto da un test di regressione per Windows.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, node.js
Ambito
cli, operating-systems
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.