Open
Description
- Version: node v13.8.0
- Platform: Win 10 64-bit
- Subsystem: Git For Windows 2.25.0, mintty 3.1.0 (x86_64-pc-msys)
What steps will reproduce the bug?
#!/usr/bin/env node
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
readline.question('> ', answer => {
console.log('answer', answer);
readline.close();
});
Running the above relying on the hash-bang/she-bang, ./readline.js
, will make it hang.
Running the above using node, node readline.js
, everything works as expected
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
The program should exit back to the shell after the user has pressed Enter
What do you see instead?
The program hangs and I can't kill it either by Ctrl+D nor Ctrl+C
Additional information
A workaround is to wrap the close()
call in a setTimeout
like so
#!/usr/bin/env node
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
readline.question('> ', answer => {
console.log('answer', answer);
setTimeout(() => readline.close());
});
This comment is similar, but that one states that it works in Win 10. That is not my experience.
#17495 (comment)