Skip to content

Use PowerShell call operator when shell integration is unavailable#14585

Open
owevertonguedes wants to merge 1 commit into
microsoft:mainfrom
owevertonguedes:fix/powershell-call-operator-no-shell-integration
Open

Use PowerShell call operator when shell integration is unavailable#14585
owevertonguedes wants to merge 1 commit into
microsoft:mainfrom
owevertonguedes:fix/powershell-call-operator-no-shell-integration

Conversation

@owevertonguedes

Copy link
Copy Markdown

Closes #14583

Problem

When "Run C/C++ File" targets a terminal without shell integration, launchIntegratedTerminal falls back to buildShellCommandLine(...) + terminal.sendText(...). That fallback quotes a program path containing spaces but never prepends the PowerShell call operator, so PowerShell evaluates the quoted path as a string literal and echoes it back instead of executing the program:

PS C:\...\00 - Test> "C:\...\00 - Test\main.exe"
C:\...\00 - Test\main.exe

This matches the reported output exactly: had the shell-integration path run, the command would have been rendered as & "C:\...\main.exe".

The shell-integration path already handles PowerShell correctly (added in #14351), but its detection logic was inline and therefore unavailable to the fallback. buildShellCommandLine also carries an explicit // TODO: Support launching with PowerShell.

Change

  • Extract the existing PowerShell detection into a isPowerShellTerminal() helper (behavior unchanged, including the "assume PowerShell on Windows when the shell is unknown" fallback).
  • Reuse it in the sendText path to prepend & for PowerShell.

No behavior change for cmd.exe or POSIX shells, or for terminals that do have shell integration.

Testing

  • tsc --noEmit passes for the changed file, and eslint is clean.
  • The existing runWithoutDebugging.terminals.test.ts matrix already covers a spaced executable across the undefined / Command Prompt / PowerShell profiles, but it only exercises the shell-integration path, which is why this fallback regressed unnoticed.

I could not exercise the Windows/PowerShell fallback end-to-end (no Windows machine available), so I would appreciate a careful look at that path in review.

"Run C/C++ File" builds the command with buildShellCommandLine and sends
it via sendText when the terminal has no shell integration. That path
quotes a program path containing spaces but never prepends the call
operator, so PowerShell evaluates the quoted path as a string literal and
echoes it instead of running the program.

The shell-integration path already handles this, so extract its PowerShell
detection into isPowerShellTerminal() and reuse it in the sendText path.

Closes microsoft#14583
@owevertonguedes
owevertonguedes requested a review from a team as a code owner July 18, 2026 13:03
@github-project-automation github-project-automation Bot moved this to Pull Request in cpptools Jul 18, 2026
@owevertonguedes

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@bobbrow

bobbrow commented Jul 20, 2026

Copy link
Copy Markdown
Member

@owevertonguedes, so are there versions of PowerShell that do not support shell integration, or is there some VS Code bug where it fails to activate? The code changes look reasonable, but I'd like to understand the case where shell integration doesn't work with PowerShell.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes “Run C/C++ File” on PowerShell terminals when shell integration is unavailable by ensuring the command is invoked with the PowerShell call operator so spaced executable paths are executed rather than echoed.

Changes:

  • Extracts PowerShell terminal detection into a reusable isPowerShellTerminal() helper.
  • Reuses that helper in the no-shell-integration fallback to prefix commands with & for PowerShell.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 125 to +128
const cmdLine: string = buildShellCommandLine('', program, args, true);
this.terminal.sendText(cmdLine);
// buildShellCommandLine quotes the path, and PowerShell evaluates a quoted path as a string
// literal instead of running it, so the call operator is required to invoke it.
this.terminal.sendText(this.isPowerShellTerminal() ? `& ${cmdLine}` : cmdLine);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Pull Request

Development

Successfully merging this pull request may close these issues.

"Run C/C++ File" fails in PowerShell if path has spaces (missing & call operator)

3 participants