Synchronously reading stdin in Windows

前端 未结 2 952
清酒与你
清酒与你 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

提交回复
热议问题