检查流是否为process.stdout [英] Check if a stream is process.stdout
问题描述
是否有一种优雅的方法来确定流是否为process.stdout
Is there an elegant way to determine if a stream is process.stdout
我正在使用流,并且希望结束流,但是发现如果流是process.stdout
,则会抛出错误,因为process.stdout
是
I am working with streams and will like to end the stream, but found out that if the stream is process.stdout
an error is thrown because process.stdout
is a special stream that cannot be closed. So want to end all streams except it's process.stdout
我尝试使用try and catch,但是process.stdout
错误结束了节点进程,忽略了try and catch.
I tried using a try and catch, but the process.stdout
error ends the node process, ignoring the try and catch.
推荐答案
也许这对我来说太幼稚了,但我认为您可以使用!==
进行检查:
Perhaps this is naive of me, but I'd think you can just check with !==
:
if (theStream !== process.stdout) {
theStream.end();
}
流是对象,只有一个process.stdout
,所以...
Streams are objects, and there's only one process.stdout
, so...
这篇关于检查流是否为process.stdout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!