Skip to content

Commit ac9d3e2

Browse files
committed
Only run workaround if running batch files or cmd.exe
1 parent c014416 commit ac9d3e2

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

cmd/state-exec/cmd_windows.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@ package main
22

33
import (
44
"os/exec"
5+
"path/filepath"
6+
"strings"
57
"syscall"
68
)
79

810
func Command(name string, arg ...string) *exec.Cmd {
911
cmd := exec.Command(name, arg...)
1012

11-
// Go currently does not escape arguments properly on Windows, it account for spaces and tab characters, but not
12-
// other characters that need escaping such as `<` and `>`.
13-
// This can be dropped once we update to a Go version that fixes this bug: https://github.com/golang/go/issues/68313
14-
cmd.SysProcAttr = &syscall.SysProcAttr{CmdLine: makeCmdLine(cmd.Args)}
13+
exeName := filepath.Base(strings.ToLower(name))
14+
if exeName == "cmd" || strings.HasSuffix(exeName, ".bat") {
15+
// Go currently does not escape arguments properly on Windows, it account for spaces and tab characters, but not
16+
// other characters that need escaping such as `<` and `>`.
17+
// This can be dropped once we update to a Go version that fixes this bug: https://github.com/golang/go/issues/68313
18+
cmd.SysProcAttr = &syscall.SysProcAttr{CmdLine: makeCmdLine(cmd.Args)}
19+
}
1520

1621
return cmd
1722
}

internal/osutils/exeutils_windows.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package osutils
33
import (
44
"os"
55
"os/exec"
6+
"path/filepath"
67
"strings"
78
"syscall"
89

@@ -21,10 +22,13 @@ func init() {
2122
func Command(name string, arg ...string) *exec.Cmd {
2223
cmd := exec.Command(name, arg...)
2324

24-
// Go currently does not escape arguments properly on Windows, it account for spaces and tab characters, but not
25-
// other characters that need escaping such as `<` and `>`.
26-
// This can be dropped once we update to a Go version that fixes this bug: https://github.com/golang/go/issues/68313
27-
cmd.SysProcAttr = &syscall.SysProcAttr{CmdLine: makeCmdLine(cmd.Args)}
25+
exeName := filepath.Base(strings.ToLower(name))
26+
if exeName == "cmd" || strings.HasSuffix(exeName, ".bat") {
27+
// Go currently does not escape arguments properly on Windows, it account for spaces and tab characters, but not
28+
// other characters that need escaping such as `<` and `>`.
29+
// This can be dropped once we update to a Go version that fixes this bug: https://github.com/golang/go/issues/68313
30+
cmd.SysProcAttr = &syscall.SysProcAttr{CmdLine: makeCmdLine(cmd.Args)}
31+
}
2832

2933
return cmd
3034
}

0 commit comments

Comments
 (0)