Files
mailadmin/backend/src/utils/shell.ts
2026-04-26 13:47:35 -05:00

22 lines
655 B
TypeScript

import { execFile } from 'node:child_process';
export interface ShellResult {
stdout: string;
stderr: string;
}
export function run(cmd: string, args: string[], timeoutMs = 120000): Promise<ShellResult> {
return new Promise((resolve, reject) => {
execFile(cmd, args, { timeout: timeoutMs, maxBuffer: 10 * 1024 * 1024 }, (error, stdout, stderr) => {
if (error) {
const err = new Error(`Command failed: ${cmd} ${args.join(' ')}\n${stderr || error.message}`);
(err as any).stdout = stdout;
(err as any).stderr = stderr;
reject(err);
return;
}
resolve({ stdout, stderr });
});
});
}