const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
setTimeout(() => {
rl.close();
}, 1000);
setInterval(() => {
console.log('test')
}, 1000);
win10 output(empty)
linux output
test
test
...
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
setTimeout(() => {
rl.close(); // process.stdin.isRaw =false
process.stdin.setRawMode(true); //stop at here
console.log("asd");
}, 1000);
this code will block without any error
rl.close() with process.stdin.pause();
process.stdin.setRawMode(false);, the output is the same (win10 empty)//test.js
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
setTimeout(() => {
process.stdin.pause();
process.stdin.setRawMode(false);
setInterval(() => {
console.log("test");
}, 1000);
}, 1000);
console.log to fs.writeFileSync ,it is ok.console.log and fs.writeFileSync , the process seems like block after console.log const readline = require("readline");
const fs = require("fs");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
setTimeout(() => {
process.stdin.pause();
process.stdin.setRawMode(false);
setInterval(() => {
fs.writeFileSync("./temp", "test2", { flag: "a" });
console.log("test");
}, 1000);
}, 1000);
terminal output is empty,file ./temp only has one string test2
$ cat ./temp
$ test2
I have looked at the docs,but I'm still confused with these result. Or if these are not bug, what is the recommend way to repeat use readline.createInterface and close readline ?
execute rl.terminal = false before rl.close()can solve this problem.
Node 14.6 has fixed this problem.
Bisected to https://github.com/nodejs/node/commit/a9ca4204e0fff3783211dec65e4548318a9395e3 (precisely https://github.com/libuv/libuv/commit/aeab873bbe4efb94baacc17ca9ab38a45009e6e8). This issue is fixed and should be closed.
Nice ! Thanks for the information. @chengzhuo5 @Hakerh400