码迷,mamicode.com
首页 > Web开发 > 详细

nodejs 命令行交互

时间:2018-02-09 15:36:50      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:reads   tip   end   use   play   log   ejs   style   res   

人机交互

function readSyncByfs(tips) {
    tips = tips || ‘> ‘;
    process.stdout.write(tips);
    process.stdin.pause();

    const buf = Buffer.allocUnsafe(10000);
    let response = fs.readSync(process.stdin.fd, buf, 0, 10000, 0);
    process.stdin.end();

    return buf.toString(‘utf8‘, 0, response).trim();
}


var a = readSyncByfs(‘请输入任意字符:‘);
var a = readSyncByfs(‘‘);
console.log(a);

 

nodejs 命令行交互

标签:reads   tip   end   use   play   log   ejs   style   res   

原文地址:https://www.cnblogs.com/CyLee/p/8434406.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!