I know that I can fire child processes with NodeJS and get their stdout. However, I'd like to retrieve stdout in real-time as they come because I am running a program that runs longer. Is there a way to do that in NodeJS?
This is the documentation I tried to look into: http://nodejs.org/docs/v0.5.8/api/child_processes.html#child_process.exec
Help? Ideas? Modules? Hacks?
Child process stdout/stdin/stderr are Streams.
Check this page section for more information: http://nodejs.org/docs/latest/api/child_process.html#child_process_child_process_spawn_command_args_options
The example on this section:
var util = require('util'),
spawn = require('child_process').spawn,
ls = spawn('ls', ['-lh', '/usr']);
ls.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
ls.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
ls.on('exit', function (code) {
console.log('child process exited with code ' + code);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With