Writing standard output and error
As the previous recipe describes, each process has stdin
, a stdout
and stderr
file descriptors. The standard approach is the use of stdout
as a process output and stderr
as process error output. As these are the file descriptors, the destination where the data is written could be anything, from the console to the socket. This recipe will show you how to write the stdout
and stderr
.
How to do it...
- Open the console and create the folder
chapter05/recipe02
. - Navigate to the directory.
- Create the
stdouterr.go
file with the following content:
package main import ( "fmt" "io" "os" ) func main() { // Simply write string io.WriteString(os.Stdout, "This is string to standard output.\n") io.WriteString(os.Stderr, "This is string to standard error output.\n") // Stdout/err implements // writer interface buf := []byte...