|
|
@ -28,7 +28,7 @@ exports.execFile = function (file /* args, options, callback */) { |
|
|
|
var options = { encoding: 'utf8' |
|
|
|
, timeout: 0 |
|
|
|
, maxBuffer: 200*1024 |
|
|
|
, killSignal: 'SIGKILL' |
|
|
|
, killSignal: 'SIGTERM' |
|
|
|
, cwd: null |
|
|
|
, env: null |
|
|
|
}; |
|
|
@ -62,18 +62,24 @@ exports.execFile = function (file /* args, options, callback */) { |
|
|
|
var stderr = ""; |
|
|
|
var killed = false; |
|
|
|
var exited = false; |
|
|
|
var timeoutId; |
|
|
|
|
|
|
|
function exithandler (code, signal) { |
|
|
|
if (timeoutId) clearTimeout(timeoutId); |
|
|
|
if (exited) return; |
|
|
|
exited = true; |
|
|
|
|
|
|
|
if (timeoutId) { |
|
|
|
clearTimeout(timeoutId); |
|
|
|
timeoutId = null; |
|
|
|
} |
|
|
|
|
|
|
|
if (!callback) return; |
|
|
|
|
|
|
|
if (code === 0 && signal === null) { |
|
|
|
callback(null, stdout, stderr); |
|
|
|
} else { |
|
|
|
var e = new Error("Command failed: " + stderr); |
|
|
|
e.killed = killed; |
|
|
|
e.killed = child.killed || killed; |
|
|
|
e.code = code; |
|
|
|
e.signal = signal; |
|
|
|
callback(e, stdout, stderr); |
|
|
@ -81,14 +87,13 @@ exports.execFile = function (file /* args, options, callback */) { |
|
|
|
} |
|
|
|
|
|
|
|
function kill () { |
|
|
|
var c = child.kill(options.killSignal); |
|
|
|
killed = true; |
|
|
|
child.kill(options.killSignal); |
|
|
|
process.nextTick(function () { |
|
|
|
exithandler(null, options.killSignal) |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
var timeoutId; |
|
|
|
if (options.timeout > 0) { |
|
|
|
timeoutId = setTimeout(function () { |
|
|
|
kill(); |
|
|
@ -113,8 +118,6 @@ exports.execFile = function (file /* args, options, callback */) { |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
var pid = child.pid; |
|
|
|
|
|
|
|
child.addListener("exit", exithandler); |
|
|
|
|
|
|
|
return child; |
|
|
@ -126,6 +129,8 @@ function ChildProcess () { |
|
|
|
|
|
|
|
var self = this; |
|
|
|
|
|
|
|
this.killed = false; |
|
|
|
|
|
|
|
var gotCHLD = false; |
|
|
|
var exitCode; |
|
|
|
var termSignal; |
|
|
@ -172,6 +177,7 @@ util.inherits(ChildProcess, EventEmitter); |
|
|
|
|
|
|
|
ChildProcess.prototype.kill = function (sig) { |
|
|
|
if (this._internal.pid) { |
|
|
|
this.killed = true; |
|
|
|
if (!constants) constants = process.binding("constants"); |
|
|
|
sig = sig || 'SIGTERM'; |
|
|
|
if (!constants[sig]) throw new Error("Unknown signal: " + sig); |
|
|
|