Eric
Eric

Reputation: 827

Node.js exec call never calls callback

I have a Node.js script which makes a call to exec but it never calls the callback. The code:

var exec = require('child_process').exec;
exec("{COMMAND} > results.log", function (error, stdout, stderr) {
  console.log('callback called!'); // this never gets called.
});

I'm using async lib and I'm relying on the exec callback to be called so I can in turn call an async callback to continue execution flow. The command does indeed get executed, as I see the output to the results.log file. What am I doing wrong here?

Upvotes: 2

Views: 939

Answers (1)

adeneo
adeneo

Reputation: 318322

You're piping the returned result into another file, so it never returns to Node.

exec("{COMMAND}", function (error, stdout, stderr) {
  console.log('callback called!'); // this never gets called.
});

Upvotes: 2

Related Questions