You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The first time the readline interface is created (in read), all your input is consumed. The second time, because the data is consumed, the event loop empties before the promise managing readline ever settles, and the program just exits.
Some options for changing read's behavior
Check input.readableEnded and watching for the readline close event, but that will just give an opportunity for a more meaningful error message, not actual read the data the way you expect.
Use fs.read to read the input stream one character at a time, provided it supplies a file descriptor. There are probably some edge cases where this won't work.
Restructure the read module to provide an object that manages a readline interface so that calling code can hang on to it and not implicitly create several readline interfaces. The limitation here is that it still won't work for subsequent calls to read.
Using
read
to prompt multiple times fails after the first line when:setTimeout(f)
withf()
seems to "fix" the issue)Test case
x.js
Interactive user input in terminal: works
Non-interactive input from file/pipe: only reads first line
Solution?
I've replaced my use of
read
with the following code, which has fewer features but works:The text was updated successfully, but these errors were encountered: