Roni Riska | fc77ebb | 2019-09-26 08:20:44 +0300 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "os/exec" |
| 6 | ) |
| 7 | |
| 8 | type cmdRunner struct { |
| 9 | exe string |
| 10 | args []string |
| 11 | cmd *exec.Cmd |
| 12 | } |
| 13 | |
| 14 | func (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 | |
| 28 | func (r *cmdRunner) kill() error { |
| 29 | return r.cmd.Process.Kill() |
| 30 | } |
| 31 | |
| 32 | func makeRunner(exe string, arg ...string) cmdRunner { |
| 33 | r := cmdRunner{exe: exe, args: arg} |
| 34 | return r |
| 35 | } |