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

Skip to content

Commit 5a5d8d7

Browse files
committed
flake: fix WorkspaceSSHExec exit code 1 on Windows shells
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]>
1 parent 6d39077 commit 5a5d8d7

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

agent/agentssh/agentssh.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,9 +917,23 @@ func (s *Server) CreateCommand(ctx context.Context, script string, env []string,
917917

918918
// OpenSSH executes all commands with the users current shell.
919919
// We replicate that behavior for IDE support.
920+
//
921+
// On Windows, the correct caller flag depends on the shell:
922+
// - cmd.exe -> /c
923+
// - powershell/pwsh -> -Command
924+
// - other shells (e.g. bash.exe from Git Bash) -> -c
920925
caller := "-c"
921926
if runtime.GOOS == "windows" {
922-
caller = "/c"
927+
base := strings.ToLower(filepath.Base(shell))
928+
switch {
929+
case base == "cmd.exe":
930+
caller = "/c"
931+
case strings.Contains(base, "powershell") || base == "pwsh.exe":
932+
caller = "-Command"
933+
default:
934+
// Fall back to POSIX-style -c for shells like bash.exe/sh.exe on Windows
935+
caller = "-c"
936+
}
923937
}
924938
name := shell
925939
args := []string{caller, script}

0 commit comments

Comments
 (0)