nodejs 命令行交互

人机交互

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);

 

posted @ 2018-02-09 10:25  贝尔塔猫  阅读(534)  评论(0编辑  收藏  举报