|
|
@ -62,14 +62,23 @@ exports.execFile = function (file /* args, options, callback */) { |
|
|
|
var stderr = ""; |
|
|
|
var killed = false; |
|
|
|
|
|
|
|
function kill(){ |
|
|
|
if (killed) return; |
|
|
|
try { |
|
|
|
child.kill(options.killSignal); |
|
|
|
} catch (err) { |
|
|
|
if ("No such process" !== err.message) { |
|
|
|
throw err; |
|
|
|
} |
|
|
|
} |
|
|
|
killed = true; |
|
|
|
} |
|
|
|
|
|
|
|
var timeoutId; |
|
|
|
if (options.timeout > 0) { |
|
|
|
timeoutId = setTimeout(function () { |
|
|
|
if (!killed) { |
|
|
|
child.kill(options.killSignal); |
|
|
|
killed = true; |
|
|
|
kill(); |
|
|
|
timeoutId = null; |
|
|
|
} |
|
|
|
}, options.timeout); |
|
|
|
} |
|
|
|
|
|
|
@ -78,30 +87,29 @@ exports.execFile = function (file /* args, options, callback */) { |
|
|
|
|
|
|
|
child.stdout.addListener("data", function (chunk) { |
|
|
|
stdout += chunk; |
|
|
|
if (!killed && stdout.length > options.maxBuffer) { |
|
|
|
child.kill(options.killSignal); |
|
|
|
killed = true; |
|
|
|
if (stdout.length > options.maxBuffer) { |
|
|
|
kill(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
child.stderr.addListener("data", function (chunk) { |
|
|
|
stderr += chunk; |
|
|
|
if (!killed && stderr.length > options.maxBuffer) { |
|
|
|
child.kill(options.killSignal); |
|
|
|
killed = true; |
|
|
|
if (stderr.length > options.maxBuffer) { |
|
|
|
kill(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
child.addListener("exit", function (code, signal) { |
|
|
|
if (timeoutId) clearTimeout(timeoutId); |
|
|
|
if (!callback) return; |
|
|
|
if (code === 0 && signal === null) { |
|
|
|
if (callback) callback(null, stdout, stderr); |
|
|
|
callback(null, stdout, stderr); |
|
|
|
} else { |
|
|
|
var e = new Error("Command failed: " + stderr); |
|
|
|
e.killed = killed; |
|
|
|
e.code = code; |
|
|
|
e.signal = signal; |
|
|
|
if (callback) callback(e, stdout, stderr); |
|
|
|
callback(e, stdout, stderr); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|