I am using node.js and stdin, but the program ends before the user can input their binary to be evaluated.
let stdin = process.stdin;
process.addListener("data", function(l) {
let input = l.toString().trim();
setTimeout(function() {
console.log("You entered"+"["+input+"]"+"Calculating...")
}, 100);
console.log(parseInt(input, 2));
});
You need to call addListener
on stdin
you declared on first line, like this:
let stdin = process.stdin;
stdin.addListener("data", function(l) {
let input = l.toString().trim();
setTimeout(function() {
console.log("You entered"+"["+input+"]"+"Calculating...")
}, 100);
console.log(parseInt(input, 2));
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.