1

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.

1 Answer 1

2

java -version writes to stderr.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, and as for node, it needs --version otherwise enters REPL. Those were example I tried.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.