CombinedOutput runs the command and returns its combined standard output and standard error.
package main import ( "fmt" "log" "os/exec" ) func main() { cmd := exec.Command("sh", "-c", "echo stdout; echo 1>&2 stderr") stdoutStderr, err := cmd.CombinedOutput() if err != nil { log.Fatal(err) } fmt.Printf("%s\n", stdoutStderr) }