I want to capture all stdout and stderr messages, and parse the data and print them in my desired format. How do I do this in go?
You can use cmd.CombinedOutput
or cmd.Output
:
out, err := exec.Command("ls", "-al").CombinedOutput()
//or
out, err := exec.Command("ls", "-al").Output()