Skip to content

Commit 9eb759d

Browse files
Alireza-GholieiAlireza Gholie
andauthored
fix: support Windows in execShell by replacing /bin/sh with cmd.exe (#1389)
Co-authored-by: Alireza Gholie <[email protected]>
1 parent e745614 commit 9eb759d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

internal/nginx/exec.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,28 @@ package nginx
33
import (
44
"context"
55
"os/exec"
6+
"runtime"
67

78
"github.com/0xJacky/Nginx-UI/internal/docker"
89
"github.com/0xJacky/Nginx-UI/settings"
910
)
1011

1112
func execShell(cmd string) (stdOut string, stdErr error) {
12-
return execCommand("/bin/sh", "-c", cmd)
13+
var execCmd *exec.Cmd
14+
15+
if runtime.GOOS == "windows" {
16+
execCmd = exec.Command("cmd", "/c", cmd)
17+
} else {
18+
execCmd = exec.Command("/bin/sh", "-c", cmd)
19+
}
20+
21+
execCmd.Dir = GetNginxExeDir()
22+
bytes, err := execCmd.CombinedOutput()
23+
stdOut = string(bytes)
24+
if err != nil {
25+
stdErr = err
26+
}
27+
return
1328
}
1429

1530
func execCommand(name string, cmd ...string) (stdOut string, stdErr error) {

0 commit comments

Comments
 (0)