MCPcopy Index your code
hub / github.com/callstack/agent-device / runCmdSync

Function runCmdSync

src/utils/exec.ts:265–318  ·  view source on GitHub ↗
(cmd: string, args: string[], options: ExecOptions = {})

Source from the content-addressed store, hash-verified

263}
264
265export function runCmdSync(cmd: string, args: string[], options: ExecOptions = {}): ExecResult {
266 const executable = normalizeExecutableCommand(cmd);
267 const result = spawnSync(executable, args, {
268 cwd: options.cwd,
269 env: options.env,
270 stdio: ['pipe', 'pipe', 'pipe'],
271 encoding: options.binaryStdout ? undefined : 'utf8',
272 input: options.stdin,
273 timeout: normalizeTimeoutMs(options.timeoutMs),
274 windowsHide: true,
275 shell: false,
276 ...(options.maxBuffer !== undefined ? { maxBuffer: options.maxBuffer } : {}),
277 });
278
279 if (result.error) {
280 const code = (result.error as NodeJS.ErrnoException).code;
281 if (code === 'ETIMEDOUT') {
282 throw new AppError(
283 'COMMAND_FAILED',
284 `${executable} timed out after ${normalizeTimeoutMs(options.timeoutMs)}ms`,
285 {
286 cmd,
287 args,
288 timeoutMs: normalizeTimeoutMs(options.timeoutMs),
289 },
290 result.error,
291 );
292 }
293 if (code === 'ENOENT') {
294 throw createMissingToolError(executable, cmd, result.error);
295 }
296 throw createCommandFailedError(executable, cmd, args, result.error);
297 }
298
299 const stdoutBuffer = options.binaryStdout
300 ? Buffer.isBuffer(result.stdout)
301 ? result.stdout
302 : Buffer.from(result.stdout ?? '')
303 : undefined;
304 const stdout = options.binaryStdout
305 ? ''
306 : typeof result.stdout === 'string'
307 ? result.stdout
308 : (result.stdout ?? '').toString();
309 const stderr =
310 typeof result.stderr === 'string' ? result.stderr : (result.stderr ?? '').toString();
311 const exitCode = result.status ?? 1;
312
313 if (exitCode !== 0 && !options.allowFailure) {
314 throw createExitError(executable, cmd, args, exitCode, stdout, stderr);
315 }
316
317 return { stdout, stderr, exitCode, stdoutBuffer };
318}
319
320export function runCmdDetached(
321 cmd: string,

Callers 15

runCliFunction · 0.90
runRecordingInspectFunction · 0.90
runCleanXcuitestFunction · 0.90
runSourceCliJsonSyncFunction · 0.90
packInstalledPackageFunction · 0.90
ensureBuiltPackageFunction · 0.90
extractInstalledPackageFunction · 0.90
runHttpRequestSyncFunction · 0.90
readProcessStartTimeFunction · 0.90
readProcessCommandFunction · 0.90
exec.test.tsFile · 0.90

Calls 5

normalizeTimeoutMsFunction · 0.85
createMissingToolErrorFunction · 0.85
createCommandFailedErrorFunction · 0.85
createExitErrorFunction · 0.85

Tested by 6

runCliFunction · 0.72
runCleanXcuitestFunction · 0.72
packInstalledPackageFunction · 0.72
ensureBuiltPackageFunction · 0.72
extractInstalledPackageFunction · 0.72
listTarGzipEntriesFunction · 0.72