2

I just slumped my shoulders as I realized that os.Stdout is an os.File. I want replace stdout with an in-memory buffer to avoid writing to a file. Is there any way to create a file that lives just in memory (and I don't want to deal with a ramdisk)?

Additional context: I'm dealing with calls to fmt.Println. I don't have the option to use fmt.Fprintln, which accepts an io.Writer instead of going straight to os.Stdout.

lukad
  • 17,287
  • 3
  • 36
  • 53
Michael Whatcott
  • 5,603
  • 6
  • 36
  • 50
  • The answer is to use `os.Pipe` as [already explained](http://stackoverflow.com/a/10476304/605022). – Michael Whatcott Mar 02 '14 at 05:06
  • 1
    Normally you would do such stuff while *calling* your program, not from within your code. – Volker Mar 02 '14 at 07:28
  • Ok, the real story is that I'm creating a wrapper over fmt.Println and I want to test that it works without having to look at the console or write to a file on disk. I have to replace os.Stdout as part of the setup of my test and the reset it afterwards. – Michael Whatcott Mar 03 '14 at 04:34

0 Answers0