Display running child process' output in nodejs (windows)
Just specify that you want the child process to inherit stdio of parent one:
require('child_process').exec('node server.js', { stdio: 'inherit' });
Exec will return STDOUT
and STDERR
when the child finishes, see exec
. That's why you do not see any output, when the server starts.
What you want is fork
, which automatically connects the child process STDOUT
and STDERR
to your parent's. This is the preferred way if your child process is a node process.
If you want to use exec you can use the child processe's streams to get your data, e.g.:
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
var child_process = nw.require('child_process');
var spawn = child_process
//The following is on windows and I record stdout and stderr to my logger
var proc = spawn('cmd.exe', ['/S', '/C', script_path]);
proc.stdout.on('data', function(data) {
logger(logtag, 'proc_stdout: ' + data);
});
proc.stderr.on('data', function(data) {
logger(logtag, 'proc_stderr: ' + data);
});