mirror of
https://github.com/moghtech/komodo.git
synced 2026-07-16 14:25:33 -05:00
26 lines
587 B
TypeScript
26 lines
587 B
TypeScript
import { exec } from "child_process";
|
|
import { promisify } from "util";
|
|
import { CommandLogError } from "@monitor/types";
|
|
import { prettyStringify } from "./helpers";
|
|
|
|
export const pExec = promisify(exec);
|
|
|
|
export async function execute(
|
|
command: string,
|
|
commandForLog?: string
|
|
): Promise<CommandLogError> {
|
|
try {
|
|
return {
|
|
command: commandForLog || command,
|
|
log: await pExec(command),
|
|
isError: false,
|
|
};
|
|
} catch (err) {
|
|
return {
|
|
command: commandForLog || command,
|
|
log: { stderr: prettyStringify(err) },
|
|
isError: true,
|
|
};
|
|
}
|
|
}
|