Created
September 20, 2020 06:45
-
-
Save shubhag/edd416c31d3ee6e1836a531d59837e28 to your computer and use it in GitHub Desktop.
Execute sub-process in golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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