sys.exec() no longer uses Promise

This commit is contained in:
Ryan Dahl 2010-02-19 16:55:46 -08:00
parent c04b679e12
commit de7016eac5
5 changed files with 55 additions and 57 deletions

View file

@ -138,11 +138,10 @@ exports.p = function () {
}
};
exports.exec = function (command) {
exports.exec = function (command, callback) {
var child = process.createChildProcess("/bin/sh", ["-c", command]);
var stdout = "";
var stderr = "";
var promise = new events.Promise();
child.addListener("output", function (chunk) {
if (chunk) stdout += chunk;
@ -154,13 +153,13 @@ exports.exec = function (command) {
child.addListener("exit", function (code) {
if (code == 0) {
promise.emitSuccess(stdout, stderr);
if (callback) callback(null, stdout, stderr);
} else {
promise.emitError(code, stdout, stderr);
var e = new Error("Command failed: " + stderr);
e.code = code;
if (callback) callback(e, stdout, stderr);
}
});
return promise;
};
/**