-
Notifications
You must be signed in to change notification settings - Fork 1
/
runner.go
49 lines (43 loc) · 1.03 KB
/
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
package main
import (
"os"
"os/exec"
"strings"
"time"
)
func Run(prog string, args ...string) ([]byte, error) {
cmd := strings.Split(prog, " ")
if len(cmd) > 0 {
args = append(cmd[1:], args...)
}
execCmd := exec.Command(cmd[0], args...)
ret, err := execCmd.CombinedOutput()
if len(ret) > 0 || (err != nil && err.Error() == "signal: aborted") {
err = nil //Hack to get around programs that exit non-zero or abort, we always want the output
}
//log("RUN: %s %v\n%s", cmd[0], cmdArgs, string(ret))
//log("RUN: %s %v", cmd[0], cmdArgs)
return ret, err
}
func RunRealtime(prog string, args ...string) error {
cmd := strings.Split(prog, " ")
if len(cmd) > 0 {
args = append(cmd[1:], args...)
}
execCmd := exec.Command(cmd[0], args...)
execCmd.Stdout = os.Stdout
execCmd.Stderr = os.Stderr
err := execCmd.Run()
if err != nil && err.Error() == "signal: aborted" {
err = nil
}
return err
}
func Interval(dur time.Duration, call func() error) {
for {
if err := call(); err != nil {
return
}
time.Sleep(dur)
}
}