-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
45 lines (39 loc) · 741 Bytes
/
main.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
package main
import (
"errors"
"fmt"
"os"
"os/exec"
"strconv"
"syscall"
)
func main() {
args := os.Args
n, err := strconv.Atoi(args[1])
if err != nil {
fmt.Fprint(os.Stderr, err.Error())
os.Exit(1)
}
for i := 0; i != n; i++ {
c := exec.Command(args[2], args[3:]...)
c.Stdout = os.Stdout
c.Stdin = os.Stdin
c.Stderr = os.Stderr
RunAndExitOnFail(c)
}
}
func RunAndExitOnFail(c *exec.Cmd) {
err := c.Run()
if err == nil {
return
}
if e2, ok := err.(*exec.ExitError); ok {
if s, ok := e2.Sys().(syscall.WaitStatus); ok {
if s.ExitStatus() != 0 {
os.Exit(s.ExitStatus())
}
} else {
panic(errors.New("Unimplemented for system where exec.ExitError.Sys() is not syscall.WaitStatus."))
}
}
}