| OLD | NEW |
| 1 package util | 1 package util |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 » "os/exec" | 4 » "go.skia.org/infra/go/exec" |
| 5 » "strings" | |
| 6 | |
| 7 » "github.com/skia-dev/glog" | |
| 8 ) | 5 ) |
| 9 | 6 |
| 10 // DoCmd executes the given command line string; the command being | 7 // DoCmd executes the given command line string; the command being |
| 11 // run is expected to not care what its current working directory is. | 8 // run is expected to not care what its current working directory is. |
| 12 // Returns the stdout and stderr. If there is an error, the | 9 // Returns the stdout and stderr. |
| 13 // returned error will be of type ExitError, which the caller | |
| 14 // can use to find out more about what happened. | |
| 15 func DoCmd(commandLine string) (string, error) { | 10 func DoCmd(commandLine string) (string, error) { |
| 16 » glog.Infof("Command: %q\n", commandLine) | 11 » return exec.RunSimple(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 | |
| 31 } | 12 } |
| OLD | NEW |