此代码获取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);


如您所见,我什至添加了一些超时来等待启动的过程完成。

最佳答案

java -version写入stderr

关于javascript - Node.js无法获取生成的进程的输出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21302350/

10-11 22:01