process.stdin


process.stdin 属性返回连接到 stdin (文件描述符 0) 的流。它是一个 net.Socket(它是一个 双工 流)除非 fd 0 引用一个文件,在这种情况下它是一个 可读 流。

¥The process.stdin property returns a stream connected to stdin (fd 0). It is a net.Socket (which is a Duplex stream) unless fd 0 refers to a file, in which case it is a Readable stream.

有关如何从 stdin 读取的详细信息,请参阅 readable.read()

¥For details of how to read from stdin see readable.read().

作为 双工 流,process.stdin 也可以在 "old" 模式下使用,与 v0.10 之前为 Node.js 编写的脚本兼容。有关详细信息,请参阅 流兼容性

¥As a Duplex stream, process.stdin can also be used in "old" mode that is compatible with scripts written for Node.js prior to v0.10. For more information see Stream compatibility.

在 "old" 流模式下,stdin 流默认暂停,因此必须调用 process.stdin.resume() 才能从中读取。另请注意,调用 process.stdin.resume() 本身会将流切换到 "old" 模式。

¥In "old" streams mode the stdin stream is paused by default, so one must call process.stdin.resume() to read from it. Note also that calling process.stdin.resume() itself would switch stream to "old" mode.