github.com/ves/terraform@v0.8.0-beta2/helper/wrappedstreams/streams.go (about) 1 // Package wrappedstreams provides access to the standard OS streams 2 // (stdin, stdout, stderr) even if wrapped under panicwrap. 3 package wrappedstreams 4 5 import ( 6 "os" 7 8 "github.com/mitchellh/panicwrap" 9 ) 10 11 // Stdin returns the true stdin of the process. 12 func Stdin() *os.File { 13 stdin := os.Stdin 14 if panicwrap.Wrapped(nil) { 15 stdin = wrappedStdin 16 } 17 18 return stdin 19 } 20 21 // Stdout returns the true stdout of the process. 22 func Stdout() *os.File { 23 stdout := os.Stdout 24 if panicwrap.Wrapped(nil) { 25 stdout = wrappedStdout 26 } 27 28 return stdout 29 } 30 31 // Stderr returns the true stderr of the process. 32 func Stderr() *os.File { 33 stderr := os.Stderr 34 if panicwrap.Wrapped(nil) { 35 stderr = wrappedStderr 36 } 37 38 return stderr 39 } 40 41 // These are the wrapped streams. There doesn't appear to be a negative 42 // impact of opening these files even if the file descriptor doesn't exist. 43 var ( 44 wrappedStdin = os.NewFile(uintptr(3), "stdin") 45 wrappedStdout = os.NewFile(uintptr(4), "stdout") 46 wrappedStderr = os.NewFile(uintptr(5), "stderr") 47 )