-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.go
More file actions
61 lines (49 loc) · 1.02 KB
/
Copy pathrun.go
File metadata and controls
61 lines (49 loc) · 1.02 KB
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
55
56
57
58
59
60
61
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"os/exec"
)
var stats = false
func init() {
cmdRun.Flag.BoolVar(&stats, "stats", false,
"Enable stats tracking to file stats.log")
}
var cmdRun = &Command{
Run: runRun,
UsageLine: "run",
Short: "runs the configuration",
Long: ``,
Flag: flag.NewFlagSet("run", flag.ExitOnError),
CustomFlags: false,
}
func runRun(cmd *Command, args []string) {
config, err := parseConfiguration()
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
return
}
c := exec.Command("bash", "-c", config.Run)
c.Stdin = os.Stdin
c.Stdout = os.Stdout
c.Stderr = os.Stderr
if err = c.Start(); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
return
}
if err = c.Wait(); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
}
if stats {
usage := c.ProcessState.SysUsage()
f, err := os.Create("stats.log")
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
}
defer f.Close()
enc := json.NewEncoder(f)
enc.Encode(usage)
}
}