fix: use cmd /c on Windows for shell command execution

The exec tool was hardcoded to use 'sh -c' which doesn't exist on Windows,
causing all tool calls to fail silently in gateway mode.
This commit is contained in:
mxrain
2026-02-12 14:21:04 +08:00
committed by lxowalle
parent 1d143fa10a
commit 53c69ae41e

View File

@@ -8,6 +8,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime"
"strings" "strings"
"time" "time"
) )
@@ -91,7 +92,12 @@ func (t *ExecTool) Execute(ctx context.Context, args map[string]interface{}) (st
cmdCtx, cancel := context.WithTimeout(ctx, t.timeout) cmdCtx, cancel := context.WithTimeout(ctx, t.timeout)
defer cancel() defer cancel()
cmd := exec.CommandContext(cmdCtx, "sh", "-c", command) var cmd *exec.Cmd
if runtime.GOOS == "windows" {
cmd = exec.CommandContext(cmdCtx, "cmd", "/c", command)
} else {
cmd = exec.CommandContext(cmdCtx, "sh", "-c", command)
}
if cwd != "" { if cwd != "" {
cmd.Dir = cwd cmd.Dir = cwd
} }