From 7e57c1b1dcd451a086088ff8ee1bcec7d9fa2287 Mon Sep 17 00:00:00 2001 From: Pascal Breuninger Date: Tue, 14 Jan 2025 10:12:11 +0100 Subject: [PATCH] fix(devcontainer): use the default shell on Windows for `initializeCommand` --- pkg/devcontainer/run.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/devcontainer/run.go b/pkg/devcontainer/run.go index 7671c1236..66e24cb2a 100644 --- a/pkg/devcontainer/run.go +++ b/pkg/devcontainer/run.go @@ -208,11 +208,23 @@ func runInitializeCommand( return nil } + shellArgs := []string{"sh", "-c"} + // According to the devcontainer spec, `initializeCommand` needs to be run on the host. + // On Windows we can't assume everyone has `sh` added to their PATH so we need to use Windows default shell (usually cmd.exe) + if runtime.GOOS == "windows" { + comSpec := os.Getenv("COMSPEC") + if comSpec != "" { + shellArgs = []string{comSpec, "/c"} + } else { + shellArgs = []string{"cmd.exe", "/c"} + } + } + for _, cmd := range config.InitializeCommand { // should run in shell? var args []string if len(cmd) == 1 { - args = []string{"sh", "-c", cmd[0]} + args = []string{shellArgs[0], shellArgs[1], cmd[0]} } else { args = cmd }