| OLD | NEW |
| 1 package util | 1 package util |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 » "go.skia.org/infra/go/exec" | 4 » "os/exec" |
| 5 » "strings" |
| 6 |
| 7 » "github.com/skia-dev/glog" |
| 5 ) | 8 ) |
| 6 | 9 |
| 7 // DoCmd executes the given command line string; the command being | 10 // DoCmd executes the given command line string; the command being |
| 8 // run is expected to not care what its current working directory is. | 11 // run is expected to not care what its current working directory is. |
| 9 // Returns the stdout and stderr. | 12 // Returns the stdout and stderr. If there is an error, the |
| 13 // returned error will be of type ExitError, which the caller |
| 14 // can use to find out more about what happened. |
| 10 func DoCmd(commandLine string) (string, error) { | 15 func DoCmd(commandLine string) (string, error) { |
| 11 » return exec.RunSimple(commandLine) | 16 » glog.Infof("Command: %q\n", commandLine) |
| 17 » programAndArgs := strings.SplitN(commandLine, " ", 2) |
| 18 » program := programAndArgs[0] |
| 19 » args := []string{} |
| 20 » if len(programAndArgs) > 1 { |
| 21 » » args = strings.Split(programAndArgs[1], " ") |
| 22 » } |
| 23 » cmd := exec.Command(program, args...) |
| 24 » message, err := cmd.CombinedOutput() |
| 25 » glog.Infof("StdOut + StdErr: %s\n", string(message)) |
| 26 » if err != nil { |
| 27 » » glog.Errorf("Exit status: %s\n", err) |
| 28 » » return string(message), err |
| 29 » } |
| 30 » return string(message), nil |
| 12 } | 31 } |
| OLD | NEW |