2021-01-28 22:59:35 -05:00
|
|
|
// +build windows
|
|
|
|
|
2021-08-18 05:42:26 -04:00
|
|
|
package processgroup
|
2021-01-28 22:11:39 -05:00
|
|
|
|
|
|
|
import (
|
2021-01-29 01:29:31 -05:00
|
|
|
"fmt"
|
2021-01-28 22:59:35 -05:00
|
|
|
"os/exec"
|
2021-01-28 22:11:39 -05:00
|
|
|
)
|
|
|
|
|
2021-01-29 01:29:31 -05:00
|
|
|
type ProcessExitGroup struct {
|
|
|
|
cmds []*exec.Cmd
|
2021-01-28 22:11:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewProcessExitGroup() (ProcessExitGroup, error) {
|
2021-01-29 01:29:31 -05:00
|
|
|
return ProcessExitGroup{}, nil
|
2021-01-28 22:11:39 -05:00
|
|
|
}
|
|
|
|
|
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-28 22:11:39 -05:00
|
|
|
}
|
|
|
|
|
2021-01-29 01:29:31 -05:00
|
|
|
func (g *ProcessExitGroup) AddProcess(cmd *exec.Cmd) error {
|
|
|
|
g.cmds = append(g.cmds, cmd)
|
|
|
|
return nil
|
2021-01-28 22:11:39 -05:00
|
|
|
}
|