In Golang, how to print string to STDERR?

In Golang, the fmt.Println() is convenient to print to STDOUT. But how to print string to STDERR?

In Go os package, “Stdin, Stdout, and Stderr are open Files pointing to the standard input, standard output, and standard error file descriptors.”

So, you can use the WriteString function on File on os.Stderr to print string to the STDERR. For example,

os.Stderr.WriteString("Msg to STDERRn")

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *