2
我有兴趣确定是否正在调用节点脚本,数据是否正在流入。检测节点是否收到stdin
也就是说,我想这两种情况
$ node index.js
$ ls | node index.js
区分,我发现确定的是这样的:
if(process.stdin.isTTY) {
console.log('called without pipe');
} else {
console.log('called with data streamed in');
}
是否可靠?它在语义上是否合适?
似乎没什么问题,即使是在Windows上运行。 – Keith