返回 DeepSeek-Reasonix
shell_kill_windows.go
根目录 / internal / control / shell_kill_windows.go
1 //go:build windows
2
3 package control
4
5 import (
6 "os/exec"
7 "strconv"
8
9 "reasonix/internal/proc"
10 )
11
12 // setShellKillTree hides the child's console and makes a cancelled command kill
13 // its whole process tree. Windows does not cascade a kill to child processes, so
14 // killing the shell leaves spawned commands running after a timeout; taskkill /T
15 // walks the PID tree and /F forces it.
16 func setShellKillTree(cmd *exec.Cmd) {
17 proc.HideWindow(cmd)
18 cmd.Cancel = func() error {
19 if cmd.Process == nil {
20 return nil
21 }
22 kill := exec.Command("taskkill", "/F", "/T", "/PID", strconv.Itoa(cmd.Process.Pid))
23 proc.HideWindow(kill)
24 _ = kill.Run()
25 return cmd.Process.Kill()
26 }
27 }
28
28 lines GO