You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What steps will reproduce the problem?
======================================
Consider the following bugged program:
-=-=- test.go -=-=-
package main;
import "io";
import "os";
import "fmt";
func main() {
io.Copy(os.Stdin, os.Stdout);
fmt.Printf("Got EOF -- bye\n");
}
-=-=- test.go -=-=-
What is the expected output?
============================
The /intended/ output was that input would be copied to output. In the echo | case, the
data would be produced in stdout and the program terminated.
What do you see instead?
========================
When interactive, the program /seems/ to work. echo |, on the other hand, hangs.
Which compiler are you using (5g, 6g, 8g, gccgo)?
=================================================
go run
Which operating system are you using?
=====================================
Linux
Which version are you using? (run 'go version')
================================================
go version go1.0.2
Please provide any additional information below.
================================================
Now as pointed out, the program is bugged. If you haven't figured out why, I'll give
you a sec to go back to the top and find out.
Got it? I sure didn't.
Not until someone pointed out that my arguments to Copy() were backwards. Coming from
UNIX, DOS, etc, the instinctive copy arguments are src -> dest. I have no issue with
Go reversing those if that makes sense, and this is not really what this bug report is
about (though it is a little confusing to newcomers).
No, the real issue I'm raising here is that Stdin fit in the Writer hole and Stdout fit
in the Reader hole.
Looking at the docs, both Stdin and Stdout (as well as Stderr) are File's. I can
understand why this was done, but it certainly doesn't fit right with some operations
like Copy() that depend on the interfacing to make sure the programmer isn't surprised.
I'm not sure what can be done, only that I figured that the subtlety of this bug would
make it worth consideration for the design and implementation teams. Ideally, given
that Copy() will certainly feel odd to other newcomers besides myself (I hope I'm not
*THAT* odd), it would seem to me that Stdin should only implement Reader and
Stdout/Stderr only implement Writer.
It's not a killer problem, but it did cause some head scratching a little while ago
while trying to make a websocket command-line client work.
The text was updated successfully, but these errors were encountered:
by rich.harkins:
The text was updated successfully, but these errors were encountered: