开发者

Can I check stdout in NodeJS in real-time?

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?

Th开发者_开发问答is 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);
});


ps.stdout.on('data', function (data) {
   //...
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜