34 lines
881 B
JavaScript
34 lines
881 B
JavaScript
|
// Generated by CoffeeScript 1.9.3
|
||
|
(function() {
|
||
|
var child_process;
|
||
|
|
||
|
child_process = require('child_process');
|
||
|
|
||
|
module.exports = function(cmd, max_wait, options) {
|
||
|
var err, orig_write, status, stderr, stdout, t0;
|
||
|
options.timeout = max_wait;
|
||
|
stdout = stderr = '';
|
||
|
status = 0;
|
||
|
t0 = Date.now();
|
||
|
orig_write = process.stderr.write;
|
||
|
process.stderr.write = function() {};
|
||
|
try {
|
||
|
stdout = child_process.execSync(cmd, options);
|
||
|
process.stderr.write = orig_write;
|
||
|
} catch (_error) {
|
||
|
err = _error;
|
||
|
process.stderr.write = orig_write;
|
||
|
if (err.signal === 'SIGTERM' && t0 <= Date.now() - max_wait) {
|
||
|
throw new Error('Timeout');
|
||
|
}
|
||
|
stdout = err.stdout, stderr = err.stderr, status = err.status;
|
||
|
}
|
||
|
return {
|
||
|
stdout: stdout,
|
||
|
stderr: stderr,
|
||
|
status: status
|
||
|
};
|
||
|
};
|
||
|
|
||
|
}).call(this);
|