Files
komodo/util/execute.ts
2022-03-17 02:36:52 -07:00

25 lines
515 B
TypeScript

import { exec } from "child_process";
import { promisify } from "util";
import { CommandLogError } from "@monitor/types";
export const pExec = promisify(exec);
export async function execute(
command: string,
commandForLog?: string
): Promise<CommandLogError> {
try {
return {
command,
log: await pExec(command),
isError: false,
};
} catch (err) {
return {
command: commandForLog || command,
log: { stderr: JSON.stringify(err) },
isError: true,
};
}
}