此代码获得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);
正如你所看到的,我甚至添加了一些超时来等待已启动的进程完成。
答案 0 :(得分:2)
java -version
写信给stderr
。