Skip to content

Instantly share code, notes, and snippets.

@gamell
Created May 11, 2015 09:20
Show Gist options
  • Save gamell/984e651e08225374ecb7 to your computer and use it in GitHub Desktop.
Save gamell/984e651e08225374ecb7 to your computer and use it in GitHub Desktop.
function executeCommand(command, callback){
console.log("*** Executing command: " + command);
var options = {
encoding: 'utf8',
timeout: 600000000,
maxBuffer: 10 * 1024 * 2048,
killSignal: 'SIGTERM',
cwd: null,
env: null
};
// we execute the command
var child = exec(command, options);
// set all the handlers to display the output in the console
child.stdout.on('data', function (data) {
console.log(data.trim());
});
child.stderr.on('data', function (data) {
console.log("ERROR: " + data.trim());
});
child.on('error', function () {
console.log("ERROR: " + data.trim());
});
child.on('close', function () {
process.exit();
if(!!callback){
callback.call(this, child);
}
});
child.on('exit', function () {
if(!!callback){
callback(this, child);
}
});
return child;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment