oneuptime/CommonServer/Utils/Execute.ts
2024-06-10 19:40:27 +01:00

25 lines
752 B
TypeScript

import { PromiseRejectErrorFunction } from 'Common/Types/FunctionTypes';
import { ExecException, exec } from 'node:child_process';
export default class Execute {
public static executeCommand(command: string): Promise<string> {
return new Promise(
(
resolve: (output: string) => void,
reject: PromiseRejectErrorFunction
) => {
exec(
`${command}`,
(err: ExecException | null, stdout: string) => {
if (err) {
return reject(err);
}
return resolve(stdout);
}
);
}
);
}
}