Skip to content

Instantly share code, notes, and snippets.

@shubhag
Created September 20, 2020 06:45
Show Gist options
  • Save shubhag/edd416c31d3ee6e1836a531d59837e28 to your computer and use it in GitHub Desktop.
Save shubhag/edd416c31d3ee6e1836a531d59837e28 to your computer and use it in GitHub Desktop.
Execute sub-process in golang
// This method execute a command in a sub-process and outputs the generated logs to a file.
func run(f *os.File) error {
args := []string{"-c", `echo "Standard output message"; >&2 echo "Standard error message"`}
cmd := exec.Command("bash", args...)
cmd.Stdout = f
cmd.Stderr = f
return cmd.Run()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment