On Sun, Apr 3, 2022 at 8:49 AM Ramil M <mirhasa...@gmail.com> wrote: > > I want to make some example improvement suggestion in os/exec package. > However I am not sure if I need to submit code change through Gerrit or post > a new issue on GitHub first? Could you please advise?
It is not necessary to open an issue if you intend to submit a change. You can simply submit a change through Gerrit as described at https://go.dev/doc/contribute. Thanks. > CombinedOutput Example > func ExampleCmd_CombinedOutput() { > 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) > } > CombinedOutput example listed above will always print only stdout, but not > combined stdout and stderr as intended to be shown in the example. > > I propose to make a change as: > > func ExampleCmd_CombinedOutput() { > cmd := exec.Command("sh", "-c", "echo stdout; cat badfile") > stdoutStderr, err := cmd.CombinedOutput() > if err != nil { > fmt.Println("some error occured:") > fmt.Printf("%s\n", stdoutStderr) > } else { > fmt.Println("function executed successfully") > } > } > > In the snippet above, the error will occur when shell will try to cat > non-existent file, > hence we will have the execution with both stdout and stderr. When I run the original example on a Linux system, I see stdout stderr So I'm not sure why anything needs to be changed here. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVX9M%3DBm4N6YyQ3-Cq6G%3DyD72paECZHFxr0XJg5yjwn-A%40mail.gmail.com.