Check if a stream is process.stdout

China☆狼群 提交于 2020-01-25 22:07:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!