You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rfmon-to-influx/src/helper/exec.js

22 lines
617 B
JavaScript

const logger = require("./logger.js")("exec");
const { spawn } = require("child_process");
function exec(cmd, stdout_handler, stderr_handler, exit_handler){
const [bin, ...args] = cmd.split(' ')
logger.addContext("binary", "bin");
logger.debug(`Spawn process '${cmd}'`);
let proc = spawn(bin, args);
logger.debug(`Attach stdout, stderr and exit-handler if set`);
stdout_handler && proc.stdout.on('data', stdout_handler);
stderr_handler && proc.stderr.on('data', stderr_handler);
exit_handler && proc.on('exit', exit_handler);
}
// Specify exports
module.exports = {
exec
};