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.
28 lines
674 B
JavaScript
28 lines
674 B
JavaScript
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;
|
|
}
|