const childProcess = require("child_process"); const streamToLogger = require("stream-to-logger"); module.exports = function runProcess(path, args, options) { if (options.logger != null) { options.logger.info(`Starting ${path}...`); } let proc = childProcess.spawn(path, args, options); if (options.logger != null) { proc.stdout.pipe(streamToLogger(options.logger.log)); proc.stderr.pipe(streamToLogger(options.logger.error)); } proc.on("error", (err) => { if (options.logger != null) { options.logger.error(err.stack); } }); proc.on("close", (code) => { options.logger.info(`${path} exited with code ${code.toString()}.`); }); return proc; }