Skip to content

Instantly share code, notes, and snippets.

@AndrewVos
Created June 30, 2014 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewVos/4c301634c449d09670b0 to your computer and use it in GitHub Desktop.
Save AndrewVos/4c301634c449d09670b0 to your computer and use it in GitHub Desktop.
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