Discussion:
[go-nuts] Why the default print prints to Stderr?
Tong Sun
2015-06-28 19:14:57 UTC
Permalink
Hi,

Why the default print prints to Stderr?

I had always assumed that without specific instruction, print will print to
stdout, but astonished to find out that it (the built-in print) will print
to Stderr.

Why is that?

Thanks

-----------------------
package main

func main() {
print("To StdOut?\n")
}
-----------------------

$ go run StdOut.go | wc
To StdOut?
0 0 0

$ go run StdOut.go 2>&1 | wc
1 2 11
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ian Davis
2015-06-28 19:17:56 UTC
Permalink
Hi,
Why the default print prints to Stderr?
I had always assumed that without specific instruction, print will
print to stdout, but astonished to find out that it (the built-in
print) will print to Stderr.
Why is that?
This is as documented, see https://golang.org/pkg/builtin/#print

print and println are for debugging so stderr is more appropriate.

Ian
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...