Skip to content

Commit 0f1d043

Browse files
fix(devcontainer): use the default shell on Windows for
`initializeCommand`
1 parent 1def508 commit 0f1d043

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pkg/devcontainer/run.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,23 @@ func runInitializeCommand(
208208
return nil
209209
}
210210

211+
shellArgs := []string{"sh", "-c"}
212+
// According to the devcontainer spec, `initializeCommand` needs to be run on the host.
213+
// On Windows we can't assume everyone has `sh` added to their PATH so we need to use Windows default shell (usually cmd.exe)
214+
if runtime.GOOS == "windows" {
215+
comSpec := os.Getenv("COMSPEC")
216+
if comSpec != "" {
217+
shellArgs = []string{comSpec, "/c"}
218+
} else {
219+
shellArgs = []string{"cmd.exe", "/c"}
220+
}
221+
}
222+
211223
for _, cmd := range config.InitializeCommand {
212224
// should run in shell?
213225
var args []string
214226
if len(cmd) == 1 {
215-
args = []string{"sh", "-c", cmd[0]}
227+
args = []string{shellArgs[0], shellArgs[1], cmd[0]}
216228
} else {
217229
args = cmd
218230
}

0 commit comments

Comments
 (0)