Skip to content

Instantly share code, notes, and snippets.

@orlandov
Created April 14, 2010 01:10
Show Gist options
  • Select an option

  • Save orlandov/365325 to your computer and use it in GitHub Desktop.

Select an option

Save orlandov/365325 to your computer and use it in GitHub Desktop.
function run(cmd, args, callback) {
var child = spawn(command, args);
var stdout = stderr = "";
child.stdout.setEncoding('utf8');
child.stdout.addListener("data", function (chunk) { stdout += chunk; });
child.stderr.setEncoding('utf8');
child.stderr.addListener("data", function (chunk) { stderr += chunk; });
child.addListener("exit", function (code) {
if (code == 0) {
if (callback) callback(null, stdout, stderr);
} else {
var e = new Error("Command failed: " + stderr);
e.code = code;
if (callback) callback(e, stdout, stderr);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment