reverseproxy: use async exec

This commit is contained in:
Girish Ramakrishnan
2024-02-21 12:33:04 +01:00
parent 9b94cf18d0
commit c1bb4de6a3
5 changed files with 90 additions and 81 deletions

View File

@@ -29,20 +29,26 @@ function exec(tag, cmd, options, callback) {
debug(`${tag} exec: ${cmd}`);
child_process.exec(cmd, options, function (error, stdout, stderr) {
const cp = child_process.exec(cmd, options, function (error, stdout, stderr) {
let e = null;
if (error) {
e = new BoxError(BoxError.SHELL_ERROR, `${tag} errored with code ${error.code} message ${error.message}`);
e.stdout = stdout; // when promisified, this is the way to get stdout
e.stderr = stderr; // when promisified, this is the way to get stderr
debug(e.message);
debug(`${tag}: ${cmd} errored`, error);
}
callback(e, stdout);
});
if (options.input) {
cp.stdin.write(options.input);
cp.stdin.end();
}
}
// use this when you are afraid of how arguments will split up
function spawn(tag, file, args, options, callback) {
assert.strictEqual(typeof tag, 'string');
assert.strictEqual(typeof file, 'string');