github.com/bilpay-tech/air@v0.0.0-20230514155040-b55f770a4ac6/runner/util_windows.go (about) 1 package runner 2 3 import ( 4 "io" 5 "os/exec" 6 "strconv" 7 "strings" 8 ) 9 10 func (e *Engine) killCmd(cmd *exec.Cmd) (pid int, err error) { 11 pid = cmd.Process.Pid 12 // https://stackoverflow.com/a/44551450 13 kill := exec.Command("TASKKILL", "/T", "/F", "/PID", strconv.Itoa(pid)) 14 return pid, kill.Run() 15 } 16 17 func (e *Engine) startCmd(cmd string) (*exec.Cmd, io.ReadCloser, io.ReadCloser, error) { 18 var err error 19 20 if !strings.Contains(cmd, ".exe") { 21 e.runnerLog("CMD will not recognize non .exe file for execution, path: %s", cmd) 22 } 23 c := exec.Command("cmd", "/c", cmd) 24 stderr, err := c.StderrPipe() 25 if err != nil { 26 return nil, nil, nil, err 27 } 28 stdout, err := c.StdoutPipe() 29 if err != nil { 30 return nil, nil, nil, err 31 } 32 err = c.Start() 33 if err != nil { 34 return nil, nil, nil, err 35 } 36 return c, stdout, stderr, err 37 }