util/run.go (view raw)
1package util
2
3import (
4 "fmt"
5 "os/exec"
6 "strings"
7)
8
9func RunCmd(cmd string, args ...string) error {
10 // Split the command into the executable and its arguments
11 parts := strings.Fields(cmd)
12 if len(parts) == 0 {
13 return fmt.Errorf("error: is there an empty command?")
14 }
15
16 execCmd := exec.Command(parts[0], parts[1:]...)
17
18 output, err := execCmd.CombinedOutput()
19 if err != nil {
20 return fmt.Errorf("error: command %q failed with %v: %s", cmd, err, output)
21 }
22 return nil
23}