返回 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 "syscall"
9 )
10
11 func windowsBatchCommand(ctx context.Context, command string) (*exec.Cmd, bool) {
12 commandLine, ok := windowsBatchCommandLine(command)
13 return newWindowsBatchCommand(ctx, commandLine, ok)
14 }
15
16 func windowsBatchArgvCommand(ctx context.Context, command string, args []string) (*exec.Cmd, bool) {
17 commandLine, ok := windowsBatchArgvCommandLine(command, args)
18 return newWindowsBatchCommand(ctx, commandLine, ok)
19 }
20
21 func windowsCmdShellCommand(ctx context.Context, command string) (*exec.Cmd, bool) {
22 return newWindowsBatchCommand(ctx, windowsCmdCommandLine(command), true)
23 }
24
25 func newWindowsBatchCommand(ctx context.Context, commandLine string, ok bool) (*exec.Cmd, bool) {
26 if !ok {
27 return nil, false
28 }
29 cmd := exec.CommandContext(ctx, "cmd.exe")
30 // cmd.exe does not use CommandLineToArgvW. Supply the exact command line so
31 // Go does not backslash-escape the leading quoted batch path.
32 cmd.Args = nil
33 cmd.SysProcAttr = &syscall.SysProcAttr{CmdLine: commandLine}
34 return cmd, true
35 }
36
36 lines GO