|
@ -10,7 +10,7 @@ var spawn = exports.spawn = function (path, args, env, customFds) { |
|
|
return child; |
|
|
return child; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
exports.exec = function (command /*, options, callback, env */) { |
|
|
exports.exec = function (command /*, options, callback */) { |
|
|
if (arguments.length < 3) { |
|
|
if (arguments.length < 3) { |
|
|
return exports.execFile("/bin/sh", ["-c", command], arguments[1]); |
|
|
return exports.execFile("/bin/sh", ["-c", command], arguments[1]); |
|
|
} else if (arguments.length < 4) { |
|
|
} else if (arguments.length < 4) { |
|
@ -20,24 +20,42 @@ exports.exec = function (command /*, options, callback, env */) { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
exports.execFile = function (file, args /*, options, callback, env */) { |
|
|
|
|
|
|
|
|
// execFile("something.sh", { env: ENV }, funciton() { })
|
|
|
|
|
|
|
|
|
|
|
|
exports.execFile = function (file /* args, options, callback */) { |
|
|
var options = { encoding: 'utf8' |
|
|
var options = { encoding: 'utf8' |
|
|
, timeout: 0 |
|
|
, timeout: 0 |
|
|
, maxBuffer: 200*1024 |
|
|
, maxBuffer: 200*1024 |
|
|
, killSignal: 'SIGKILL' |
|
|
, killSignal: 'SIGKILL' |
|
|
|
|
|
, env: null |
|
|
}; |
|
|
}; |
|
|
|
|
|
var args, optionArg, callback; |
|
|
|
|
|
|
|
|
|
|
|
// Parse the parameters.
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof arguments[arguments.length-1] === "function") { |
|
|
|
|
|
callback = arguments[arguments.length-1]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(arguments[1])) { |
|
|
|
|
|
args = arguments[1]; |
|
|
|
|
|
if (typeof arguments[2] === 'object') optionArg = arguments[2]; |
|
|
|
|
|
} else { |
|
|
|
|
|
args = []; |
|
|
|
|
|
if (typeof arguments[1] === 'object') optionArg = arguments[1]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var callback = (arguments.length == 5 ? arguments[3] : arguments[arguments.length-1]); |
|
|
// Merge optionArg into options
|
|
|
|
|
|
if (optionArg) { |
|
|
if (arguments[2] && typeof arguments[2] == 'object') { |
|
|
|
|
|
var keys = Object.keys(options); |
|
|
var keys = Object.keys(options); |
|
|
for (var i = 0; i < keys.length; i++) { |
|
|
for (var i = 0; i < keys.length; i++) { |
|
|
var k = keys[i]; |
|
|
var k = keys[i]; |
|
|
if (arguments[2][k] !== undefined) options[k] = arguments[2][k]; |
|
|
if (optionArg[k] !== undefined) options[k] = optionArg[k]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var child = arguments[4] ? spawn(file, args, arguments[4]) : spawn(file, args); |
|
|
var child = spawn(file, args, options.env); |
|
|
var stdout = ""; |
|
|
var stdout = ""; |
|
|
var stderr = ""; |
|
|
var stderr = ""; |
|
|
var killed = false; |
|
|
var killed = false; |
|
|