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