mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-10 05:26:50 +03:00
feat: finalize first modular pack
This commit is contained in:
32
fe-app-podkop/src/helpers/executeShellCommand.ts
Normal file
32
fe-app-podkop/src/helpers/executeShellCommand.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { COMMAND_TIMEOUT } from '../constants';
|
||||
import { withTimeout } from './withTimeout';
|
||||
|
||||
interface ExecuteShellCommandParams {
|
||||
command: string;
|
||||
args: string[];
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
interface ExecuteShellCommandResponse {
|
||||
stdout: string;
|
||||
stderr: string;
|
||||
code?: number;
|
||||
}
|
||||
|
||||
export async function executeShellCommand({
|
||||
command,
|
||||
args,
|
||||
timeout = COMMAND_TIMEOUT,
|
||||
}: ExecuteShellCommandParams): Promise<ExecuteShellCommandResponse> {
|
||||
try {
|
||||
return withTimeout(
|
||||
fs.exec(command, args),
|
||||
timeout,
|
||||
[command, ...args].join(' '),
|
||||
);
|
||||
} catch (err) {
|
||||
const error = err as Error;
|
||||
|
||||
return { stdout: '', stderr: error?.message, code: 0 };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user