Open Sogrey opened 4 years ago
// 引入readline模块 var readline = require('readline'); //创建readline接口实例 var rl = readline.createInterface({ input:process.stdin, output:process.stdout }); // question方法 rl.question("你叫什么?",function(answer){ console.log("名字是:"+answer); // 不加close,则不会结束 rl.close(); }); // close事件监听 rl.on("close", function(){ // 结束程序 process.exit(0); });
// 引入readline模块 var readline = require('readline'); var rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.on('line', function(line){ switch(line.trim()) { case 'copy': console.log("复制"); break; case 'hello': rl.write("Write"); console.log('world!'); break; case 'close': rl.close(); break; default: console.log('没有找到命令!'); break; } }); rl.on('close', function() { console.log('bye bye'); process.exit(0); });
var readline = require('readline'); var rl = readline.createInterface(process.stdin, process.stdout); rl.setPrompt('Test> '); rl.prompt(); rl.on('line', function(line) { switch(line.trim()) { case 'copy': console.log("复制"); break; case 'hello': console.log('world!'); break; case 'close': rl.close(); break; default: console.log('没有找到命令!'); break; } rl.prompt(); }); rl.on('close', function() { console.log('bye bye!'); process.exit(0); });
https://blog.csdn.net/zgljl2012/article/details/48321171
Readline
输入与输出
类似命令行的输入输出
https://blog.csdn.net/zgljl2012/article/details/48321171