您不能执行“ while(done)”循环,因为这将需要阻塞输入,而node.js则不喜欢这样做。
而是设置一个在每次输入内容时都要调用的回调:
var stdin = process.openStdin();stdin.addListener("data", function(d) { // note: d is an object, and when converted to a string it will // end with a linefeed. so we (rather crudely) account for that // with toString() and then trim() console.log("you entered: [" + d.toString().trim() + "]"); });


