I'm trying to read user input from stdin, in my case, two inputs entered on separate lines. However, when I run the following code (node program.js
), it allows me to enter the first value, then I click enter
and type in the second value, but when I click enter
, it does not run the rest of my program. How do I tell it to stop reading and proceed?
process.stdin.resume();
process.stdin.setEncoding("ascii");
var input = "";
process.stdin.on("data", function (chunk) {
input += chunk;
});
process.stdin.on("end", function () {
lines = input.split("\n");
var numVals = lines[0];
process.stdout.write(numVals + "\n");
var vals = lines[1];
process.stdout.write(vals+"\n");
});
Aucun commentaire:
Enregistrer un commentaire