问题
Is there an elegant way to determine if a stream is 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
I tried using a try and catch, but the process.stdout
error ends the node process, ignoring the try and catch.
回答1:
Perhaps this is naive of me, but I'd think you can just check with !==
:
if (theStream !== process.stdout) {
theStream.end();
}
Streams are objects, and there's only one process.stdout
, so...
来源:https://stackoverflow.com/questions/41521709/check-if-a-stream-is-process-stdout