27 lines
928 B
JavaScript
27 lines
928 B
JavaScript
|
const logger = require('../libs/logger.js');
|
||
|
const { spawn } = require('child_process')
|
||
|
|
||
|
function execute(endpoint) {
|
||
|
if (!endpoint || !endpoint.command) {
|
||
|
logger.warn('no command defined');
|
||
|
return;
|
||
|
}
|
||
|
logger.debug('executing command \'' + endpoint.command + '\' with args \'' + endpoint.args + '\'...');
|
||
|
var cmd = spawn(endpoint.command, endpoint.args);
|
||
|
cmd.stdout.on('data', function(data) {
|
||
|
logger.debug(data);
|
||
|
});
|
||
|
cmd.stderr.on('data', function(data) {
|
||
|
logger.error(data);
|
||
|
});
|
||
|
cmd.on('close', function(code) {
|
||
|
logger.debug('command \'' + endpoint.command + '\' with args \'' + endpoint.args + '\' finished with exit code ' + code);
|
||
|
});
|
||
|
cmd.on('error', function(err) {
|
||
|
logger.error('command \'' + endpoint.command + '\' with args \'' + endpoint.args + '\' encountered an error >>> ' + err);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
execute
|
||
|
}
|