Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ThomasK33
Copy link
Member

@ThomasK33 ThomasK33 commented Sep 12, 2025

Improve shell command execution on Windows by using shell-specific flags

This PR enhances the shell command execution on Windows by selecting the appropriate command flag based on the shell being used:

  • cmd.exe uses /c
  • PowerShell/pwsh uses -Command
  • Other shells (like bash.exe from Git Bash) use the POSIX-style -c

This change ensures proper command execution across different shell environments on Windows systems.

Fixes: coder/internal#798

On Windows, the SSH exec path always passed '/c' regardless of shell. When the runner’s shell is PowerShell/pwsh, '/c' is invalid and the command exits 1, producing a flaky failure in WorkspaceSSHExec. Detect the resolved shell and choose the correct caller flag (cmd=/c, powershell/pwsh=-Command, others=-c) so simple commands like 'echo' succeed consistently.

Change-Id: I3ed89f9eefe22dfdf3c981d0bc266c0d75d71e08
Signed-off-by: Thomas Kosiewski <[email protected]>
Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ThomasK33 ThomasK33 marked this pull request as ready for review September 12, 2025 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flake: TestTools/WorkspaceSSHExec
1 participant