返回 DeepSeek-Reasonix
batch_command_windows.go
根目录 / internal / hook / batch_command_windows.go
1 //go:build windows
2
3 package hook
4
5 import (
6 "context"
7 "os/exec"
8
9 "reasonix/internal/proc"
10 )
11
12 func windowsBatchCommand(ctx context.Context, command string) (*exec.Cmd, bool) {
13 commandLine, ok := windowsBatchCommandLine(command)
14 return newWindowsBatchCommand(ctx, commandLine, ok)
15 }
16
17 func windowsBatchArgvCommand(ctx context.Context, command string, args []string) (*exec.Cmd, bool) {
18 commandLine, ok := windowsBatchArgvCommandLine(command, args)
19 return newWindowsBatchCommand(ctx, commandLine, ok)
20 }
21
22 func windowsCmdShellCommand(ctx context.Context, command string) (*exec.Cmd, bool) {
23 return newWindowsBatchCommand(ctx, windowsCmdCommandLine(command), true)
24 }
25
26 func newWindowsBatchCommand(ctx context.Context, commandLine string, ok bool) (*exec.Cmd, bool) {
27 if !ok {
28 return nil, false
29 }
30 cmd := proc.CommandContext(ctx, "cmd.exe")
31 // cmd.exe does not use CommandLineToArgvW. Supply the exact command line so
32 // Go does not backslash-escape the leading quoted batch path.
33 cmd.Args = nil
34 cmd.SysProcAttr.CmdLine = commandLine
35 return cmd, true
36 }
37
37 lines GO