diff --git a/src/proc.ts b/src/proc.ts index fb4bf0973..4b47b2820 100644 --- a/src/proc.ts +++ b/src/proc.ts @@ -95,7 +95,7 @@ export interface ExecutionResult { export interface ExecutionOptions { environment?: Environment; - shell?: boolean; + shell?: boolean | string; silent?: boolean; cwd?: string; encoding?: BufferEncoding; @@ -113,6 +113,18 @@ export function buildCmdStr(command: string, args?: string[]): string { return cmdarr.map(a => /[ \n\r\f;\t]/.test(a) ? `"${a}"` : a).join(' '); } +export function determineShell(command: string): string | boolean { + if (command.endsWith('.cmd') || command.endsWith('.bat')) { + return 'cmd'; + } + + if (command.endsWith('.ps1')) { + return 'powershell'; + } + + return false; +} + /** * Execute a command and return the result * @param command The binary to execute @@ -146,9 +158,10 @@ export function execute(command: string, args?: string[], outputConsumer?: Outpu log.debug(localize('execution.environment', ' with environment: {0}', JSON.stringify(final_env))); } } + const spawn_opts: proc.SpawnOptions = { env: final_env, - shell: !!options.shell + shell: options.shell ?? determineShell(command) }; if (options?.cwd !== undefined) { util.createDirIfNotExistsSync(options.cwd);