mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
sys.exec() no longer uses Promise
This commit is contained in:
parent
c04b679e12
commit
de7016eac5
5 changed files with 55 additions and 57 deletions
11
lib/sys.js
11
lib/sys.js
|
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue