blob: 0071c20107d271b5dd380731669ea3abacb23542 [file] [log] [blame]
Roni Riskafc77ebb2019-09-26 08:20:44 +03001package main
2
3import (
4 "os"
5 "os/exec"
6)
7
8type cmdRunner struct {
9 exe string
10 args []string
11 cmd *exec.Cmd
12}
13
14func (r *cmdRunner) run(result chan error) {
15 r.cmd = exec.Command(r.exe, r.args...)
16 r.cmd.Stdout = os.Stdout
17 r.cmd.Stderr = os.Stderr
18 err := r.cmd.Start()
19 go func() {
20 if err != nil {
21 result <- err
22 } else {
23 result <- r.cmd.Wait()
24 }
25 }()
26}
27
28func (r *cmdRunner) kill() error {
29 return r.cmd.Process.Kill()
30}
31
32func makeRunner(exe string, arg ...string) cmdRunner {
33 r := cmdRunner{exe: exe, args: arg}
34 return r
35}