Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package main
import (
func main() {
stdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
defer func() { os.Stdout = stdout }()
done := make(chan bool)
var testOutput bytes.Buffer
go func() {
io.Copy(&testOutput, r)
done <- true
fmt.Printf("Hello world")
os.Stdout = stdout
fmt.Printf("RESULT: %s\n", testOutput.String())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment