Synchronously reading stdin in Windows

前端 未结 2 933
清酒与你
清酒与你 2020-12-21 08:47

I\'ve been doing this to synchronously read the whole stdin data under Linux:

var buffer = fs.readFileSync(\'/dev/stdin\');

This obviously

相关标签:
2条回答
  • 2020-12-21 09:02

    The module readline-sync do the job very well.

    npm install readline-sync
    

    and then:

    var readlineSync = require('readline-sync');
    var answer = readlineSync.question('What is your favorite food? :');
    console.log('Oh, so your favorite food is ' + answer);
    

    https://www.npmjs.com/package/readline-sync

    0 讨论(0)
  • 2020-12-21 09:23
    var size = fs.fstatSync(process.stdin.fd).size;
    var buffer = size > 0 ? fs.readSync(process.stdin.fd, size)[0] : '';
    
    0 讨论(0)
提交回复
热议问题