* Spawns a given command with the specified arguments inside a shell synchronously. * * @returns The command's stdout and stderr.
(command: string, args: string[], options: SpawnSyncOptions = {})
| 85 | * @returns The command's stdout and stderr. |
| 86 | */ |
| 87 | static spawnSync(command: string, args: string[], options: SpawnSyncOptions = {}): SpawnResult { |
| 88 | // Default shell to false to prevent OS command injection: with shell: true, Node.js |
| 89 | // internally joins command + args into a single string evaluated by /bin/sh, making |
| 90 | // shell metacharacters in args exploitable. Callers that genuinely require shell |
| 91 | // features (e.g. sourcing shell scripts) may explicitly pass shell: true. |
| 92 | const commandText = `${command} ${args.join(' ')}`; |
| 93 | const env = getEnvironmentForNonInteractiveCommand(options.env); |
| 94 | |
| 95 | Log.debug(`Executing command: ${sanitize(commandText)}`); |
| 96 | |
| 97 | const { |
| 98 | status: exitCode, |
| 99 | signal, |
| 100 | stdout, |
| 101 | stderr, |
| 102 | } = _spawnSync(command, args, {...options, env, encoding: 'utf8', stdio: 'pipe'}); |
| 103 | |
| 104 | /** The status of the spawn result. */ |
| 105 | const status = statusFromExitCodeAndSignal(exitCode, signal); |
| 106 | |
| 107 | if (status === 0 || options.suppressErrorOnFailingExitCode) { |
| 108 | return {status, stdout, stderr}; |
| 109 | } |
| 110 | |
| 111 | throw new Error(sanitize(stderr)); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Spawns a given command with the specified arguments inside a shell. All process stdout |
no test coverage detected