initial commit
This commit is contained in:
21
backend/src/utils/shell.ts
Normal file
21
backend/src/utils/shell.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
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 });
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user