In Golang, how to print string to STDERR?
Posted on In QAIn 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")