nezha/pkg/utils/proccess_group_windows.go

31 lines
524 B
Go
Raw Normal View History

2021-01-28 22:59:35 -05:00
// +build windows
package utils
import (
2021-01-29 01:29:31 -05:00
"fmt"
2021-01-28 22:59:35 -05:00
"os/exec"
)
2021-01-29 01:29:31 -05:00
type ProcessExitGroup struct {
cmds []*exec.Cmd
}
func NewProcessExitGroup() (ProcessExitGroup, error) {
2021-01-29 01:29:31 -05:00
return ProcessExitGroup{}, nil
}
2021-01-29 01:29:31 -05:00
func (g *ProcessExitGroup) Dispose() error {
for _, c := range g.cmds {
if err := exec.Command("taskkill", "/F", "/T", "/PID", fmt.Sprint(c.Process.Pid)).Run(); err != nil {
return err
}
}
return nil
}
2021-01-29 01:29:31 -05:00
func (g *ProcessExitGroup) AddProcess(cmd *exec.Cmd) error {
g.cmds = append(g.cmds, cmd)
return nil
}