You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'process.stdout cannot be closed': process.stdout should behave like a standard stream #7606
// hang processsetTimeout(function(){},9999999)// in heavy development, there usually exists something that hangs the process.// we use 'process.exit' to solve this quickly.varstream=require('stream')process.stdin.pipe(newstream.PassThrough())// there can be a list of Transform.pipe(newstream.PassThrough())// there can be a list of Transform.pipe(newstream.PassThrough())// there can be a list of Transform.on('end',function(){// process.exit()// exit here will stop stdout from flushing}).pipe(process.stdout).on('finish',function(){// this event will not triggerprocess.exit()})
execution result: hangs forever
expect: process.stdout should behaves like a standard stream.
That behavior is intentional and fixes more issues than it introduces. Most programs fail very badly if stdio could be closed and in fact they did. That's why we made stdio permanent in v0.6.0.
@bnoordhuis, is this functionality the same for stdin and stderr, how can I properly attach and deattach a Writable Stream to process.stdout out so I can get all my console output to a file
Activity
bnoordhuis commentedon Jul 8, 2016
That behavior is intentional and fixes more issues than it introduces. Most programs fail very badly if stdio could be closed and in fact they did. That's why we made stdio permanent in v0.6.0.
I'll go ahead and close the issue.
Judimax commentedon Jan 28, 2019
@bnoordhuis, is this functionality the same for stdin and stderr, how can I properly attach and deattach a Writable Stream to process.stdout out so I can get all my console output to a file
sam-github commentedon Jan 31, 2019
In my opionion, node lacks
process.stdio.reopen(), or something similar -- an equivalent tofreopen(3).Judimax commentedon Jan 31, 2019
solution I implemented check if this works or its a safe solution
https://stackoverflow.com/questions/32719923/redirecting-stdout-to-file-nodejs/54407338#54407338
stream: complete pipeline with stdio
stream: complete pipeline with stdio
stream: complete pipeline with stdio
stream: complete pipeline with stdio
0xkarambit commentedon Jul 1, 2020
I think that the fact that stdout doesn't emit the "finish" event should be mentioned in the nodejs
docs under the "a note of process io" section on the page about process
https://nodejs.org/api/process.html#process_a_note_on_process_i_o
ronag commentedon Jul 1, 2020
It does emit the finish event, try:
0xkarambit commentedon Jul 2, 2020
Oh yes, it does sorry for that, I am just a beginner.