Node.js无法获得生成进程的输出

时间:2014-01-23 07:51:26

标签: javascript node.js process

此代码获得spawned process的输出。怎么了?节点版本是v0.10.22

var spawn = require('child_process').spawn;
var what = 'java';
var spawned = spawn(what,  ['-version']);

console.log('starting `'+what+' -version`');

spawned.stdout.setEncoding('utf8');
spawned.stdout.on('data', function (data) {
    console.log(data);
});

spawned.on('close', function (code) {
    console.log('process exit code ' + code);
});

var whendone = function() {
    console.log('done');
};
setTimeout(whendone,5000);

正如你所看到的,我甚至添加了一些超时来等待已启动的进程完成。

1 个答案:

答案 0 :(得分:2)

java -version写信给stderr