Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io: Cannot io.Copy from os.Stdin on Windows 7 #5481

Closed
dominikh opened this issue May 15, 2013 · 5 comments
Closed

io: Cannot io.Copy from os.Stdin on Windows 7 #5481

dominikh opened this issue May 15, 2013 · 5 comments

Comments

@dominikh
Copy link
Member

Before filing a bug, please check whether it has been fixed since the
latest release. Search the issue tracker and check that you're running the
latest version of Go:

Run "go version" and compare against
http://golang.org/doc/devel/release.html  If a newer version of Go exists,
install it and retry what you did to reproduce the problem.

Thanks.

What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
1. Compile the program from http://play.golang.org/p/bcmX4--v_j on Windows 7
2. Run the resulting program on Windows 7
3. Press a key, then hit enter

What is the expected output?
It should copy the input from stdin to stdout

What do you see instead?
0 read /dev/stdin: Not enough storage is available to process this command.

Which compiler are you using (5g, 6g, 8g, gccgo)?
8g

Which operating system are you using?
Windows 7

Which version are you using?  (run 'go version')
go version devel +8f1fb6b6f141 Mon May 13 13:04:08 2013 -0700 linux/amd64 (cross
compiled, natively compiling has the same effect)

Please provide any additional information below.
The problem here is that io.Copy uses a buffer that is 32KB big. Since we're copying
from stdin on Windows, the Read operation runs through (*File).readConsole
(os/file_windows.go), which uses the ReadConsole syscall. Due to wchars, readConsole
uses a buffer twice the size of the original one, so 64KB in this case. ReadConsole is
documented[1] to accept at most a 64K buffer, possibly less. For some reason, it fails
on exactly 64KB, which might be an error in the documentation, caused by already used
heap, or a bug (the comments below the documentation would suggest so).

I also assembled a longer Go program[2] that demonstrates that the issue boils down to
the buffer size, where it works for 2^15-1 bytes but not for 2^15.

I'm filing this as an issue on io.Copy because I'm not sure that the issue (a limited
Windows API) can be fixed in a broader scope.

[1] http://msdn.microsoft.com/en-us/library/windows/desktop/ms684958(v=vs.85)
[2] http://play.golang.org/p/tWnZuyZLPV
@alberts
Copy link
Contributor

alberts commented May 15, 2013

Comment 2:

related to issue #3376 and issue #3767?

@alexbrainman
Copy link
Member

Comment 3:

We had similar problem for writing to console. Now it is the same for reading. How about
this https://golang.org/cl/9437044 ?
Alex

Labels changed: added packagebug, os-windows.

Owner changed to @alexbrainman.

Status changed to Started.

@gopherbot
Copy link

Comment 4 by sinni800:

I have to add, when I use GoLitdeIDEs integrated console it works!
I don't even know what's up with that.

@alexbrainman
Copy link
Member

Comment 5:

@sinni800, this bug is not tickled if go program stdin is redirected - it is only broken
when it is reading from windows console. Perhaps, GoLitdeIDEs redirects whatever program
input. I don't know.
Alex

@alexbrainman
Copy link
Member

Comment 6:

This issue was closed by revision a65f861.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants