在 Windows 中同步读取 stdin [英] Synchronously reading stdin in Windows

查看:31
本文介绍了在 Windows 中同步读取 stdin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样做是为了在 Linux 下同步读取整个 stdin 数据:

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

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

这显然不适用于 Windows,因为没有/dev/stdin 文件.我能做些什么来实现同样的目标?

This obviously won't work on Windows since there is no /dev/stdin file. What could I do to achieve the same?

推荐答案

readline-sync 模块做得很好.

The module readline-sync do the job very well.

npm install readline-sync

然后:

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

这篇关于在 Windows 中同步读取 stdin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆