This code get output of spawned process. What is wrong? node version is 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);
As you can see I even added some timeout to wait for a launched process to finish.