Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

determine shell for .cmd, .bat, .ps1 #4044

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
Improvements:

- Update signing to support VSCode extension signing. [#4055](https://github.com/microsoft/vscode-cmake-tools/pull/4055)
- Ensure that any uses of `proc.spawn` work, especially for .bat and .cmd files, due to VS Code updating to Node 20. [#4037](https://github.com/microsoft/vscode-cmake-tools/issues/4037)

## 1.19.51

Bug Fixes:

- Fix generator and preferredGenerator logic. [#4031](https://github.com/microsoft/vscode-cmake-tools/issues/4031), [#4005](https://github.com/microsoft/vscode-cmake-tools/issues/4005), [#4032](https://github.com/microsoft/vscode-cmake-tools/issues/4032)


## 1.19.50

Bug Fixes:
Expand Down
19 changes: 18 additions & 1 deletion src/proc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export interface ExecutionResult {

export interface ExecutionOptions {
environment?: Environment;
shell?: boolean;
shell?: boolean | string;
silent?: boolean;
cwd?: string;
encoding?: BufferEncoding;
Expand All @@ -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
Expand Down Expand Up @@ -146,6 +158,11 @@ export function execute(command: string, args?: string[], outputConsumer?: Outpu
log.debug(localize('execution.environment', ' with environment: {0}', JSON.stringify(final_env)));
}
}

if (options.shell === undefined && process.platform === "win32") {
options.shell = determineShell(command);
}

const spawn_opts: proc.SpawnOptions = {
env: final_env,
shell: !!options.shell
Expand Down
Loading