| 1 |
define(["../fileHandleThrottle", "../messages"], function(fht, messages){ |
| 2 |
|
| 3 |
var match = process.version.match(/(\d+)\.(\d+)\.(\d+)/), |
| 4 |
versionMajor = Number(match[1]), |
| 5 |
versionMinor = Number(match[2]), |
| 6 |
versionPatch = Number(match[3]), |
| 7 |
spawn = require.nodeRequire("child_process").spawn; |
| 8 |
return { |
| 9 |
cwd:process.cwd, |
| 10 |
exit:function(code){ |
| 11 |
|
| 12 |
messages.stop(); |
| 13 |
|
| 14 |
process.exit(code); |
| 15 |
}, |
| 16 |
|
| 17 |
exec:function() { |
| 18 |
|
| 19 |
for(var command = arguments[0], args = [], i = 1; i<arguments.length-3; i++){ |
| 20 |
args.push(arguments[i]); |
| 21 |
} |
| 22 |
var |
| 23 |
errorMessage = arguments[i++], |
| 24 |
bc = arguments[i++], |
| 25 |
callback = arguments[i]; |
| 26 |
fht.enqueue(function(){ |
| 27 |
var |
| 28 |
text = "", |
| 29 |
process = spawn(command, args), |
| 30 |
status = 0, |
| 31 |
finish = function(code){ |
| 32 |
|
| 33 |
if(++status===2){ |
| 34 |
fht.release(); |
| 35 |
if(code){ |
| 36 |
bc.log("execFailed", ["message", errorMessage, "output", text]); |
| 37 |
} |
| 38 |
callback && callback(code, text); |
| 39 |
} |
| 40 |
}; |
| 41 |
|
| 42 |
process.on("exit", finish); |
| 43 |
|
| 44 |
|
| 45 |
if(versionMajor==0 && versionMinor<=7){ |
| 46 |
++status; |
| 47 |
}else{ |
| 48 |
process.on("close", finish); |
| 49 |
} |
| 50 |
process.stdout.on("data", function(data){ |
| 51 |
text+= data; |
| 52 |
}); |
| 53 |
process.stderr.on("data", function(data){ |
| 54 |
text+= data; |
| 55 |
}); |
| 56 |
}); |
| 57 |
} |
| 58 |
}; |
| 59 |
}); |
| 60 |
|