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