I am creating some child_processes with Node.js (require('child_process')
) and I want to ensure that the stdout/stderr from each child_process does not go to the terminal, because I want only the output from the parent process to get logged. Is there a way to redirect the stdout/stderr streams in the child_processes to /dev/null
or some other place that is not the terminal?
https://nodejs.org/api/child_process.html
perhaps it's just:
var n = cp.fork('child.js',[],{
stdio: ['ignore','ignore','ignore']
});
I just tried that, and that didn't seem to work.
Now I tried this:
var stdout, stderr;
if (os.platform() === 'win32') {
stdout = fs.openSync('NUL', 'a');
stderr = fs.openSync('NUL', 'a');
}
else {
stdout = fs.openSync('/dev/null', 'a');
stderr = fs.openSync('/dev/null', 'a');
}
and then this option:
stdio: ['ignore', stdout, stderr],
but that didn't do it, but it seems like using the "detached:true" option might make this work.
process.stdout.write
in your forked process? – Ringstdio
option is forspawn
, notfork
, maybe you want thesilent
option? – Home