Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
func captureStdout(f func()) string {
tempFile, _ := ioutil.TempFile("", "stdout")
oldStdout := os.Stdout
os.Stdout = tempFile
f()
os.Stdout = oldStdout
tempFile.Close()
b, _ := ioutil.ReadFile(tempFile.Name())
return string(b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.