ExecCommand executes a command using exec It returns any output/errors
(name string, arg ...string)
| 17 | // ExecCommand executes a command using exec |
| 18 | // It returns any output/errors |
| 19 | func ExecCommand(name string, arg ...string) (string, error) { |
| 20 | var err error |
| 21 | cmd := exec.Command(name, arg...) |
| 22 | outputBytes := &bytes.Buffer{} |
| 23 | cmd.Stdout = outputBytes |
| 24 | cmd.Stderr = outputBytes |
| 25 | err = cmd.Start() |
| 26 | if err != nil { |
| 27 | return "", err |
| 28 | } |
| 29 | err = cmd.Wait() // wait for command to finish |
| 30 | outstring := outputBytes.String() |
| 31 | return outstring, err |
| 32 | } |
| 33 | |
| 34 | // RunCommand executes a shell command and returns the output/error |
| 35 | func RunCommand(input string) (string, error) { |
no test coverage detected