forked from lateefj/fresh
-
Notifications
You must be signed in to change notification settings - Fork 1
/
runner.go
54 lines (43 loc) · 809 Bytes
/
runner.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package runner
import (
"flag"
"io"
"os"
"os/exec"
"strings"
)
var cmdArgs string
func init() {
flag.StringVar(&cmdArgs, "a", "", "Command line arguments to pass to the process")
}
func run() bool {
runnerLog("Running...")
var cmd *exec.Cmd
if cmdArgs != "" {
args := strings.Split(cmdArgs, " ")
cmd = exec.Command(buildPath(), args...)
} else {
cmd = exec.Command(buildPath())
}
stderr, err := cmd.StderrPipe()
if err != nil {
fatal(err)
}
stdout, err := cmd.StdoutPipe()
if err != nil {
fatal(err)
}
err = cmd.Start()
if err != nil {
fatal(err)
}
go io.Copy(appLogWriter{}, stderr)
go io.Copy(appLogWriter{}, stdout)
go func() {
<-stopChannel
pid := cmd.Process.Pid
runnerLog("Stopping PID %d", pid)
cmd.Process.Signal(os.Interrupt)
}()
return true
}