-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
windows: detect + handle console in os.File.Write #3376
Labels
Comments
Please, try go run astmangle.go 2> output.txt and then look inside of output.txt file. It is all there. I do not know why we can't see it on console. The output is utf8, perhaps some chars are not interpreted properly by windows console. Labels changed: added os-windows. Owner changed to @alexbrainman. Status changed to WorkingAsIntended. |
This makes no sense to me. Try this: package main import ( "fmt" "os/exec" ) func main() { cmd := exec.Command("go", "list", "-json", "all") out, err := cmd.Output() if err != nil { panic(err) } fmt.Printf("%d\n", len(out)) fmt.Printf("%x\n", out[:32767]) } I get about 32k characters, and then garbage Attachments:
|
I filed a PowerShell bug since the problem appears there too: https://connect.microsoft.com/PowerShell/feedback/details/733023 |
fullung, You are correct, write fails: package main import ( "fmt" "log" "os" "os/exec" "syscall" ) func toStdout(d []byte) { const max = 1<<10 for { if len(d) <= max { os.Stdout.Write(d) return } os.Stdout.Write(d[:max]) d = d[max:] } } func main() { cmd := exec.Command("go", "list", "-json", "all") out, err := cmd.Output() if err != nil { log.Fatal(err) } fmt.Printf("%d\n", len(out)) toStdout(out) _, err = fmt.Printf("%x\n", out[:32767]) if err != nil { log.Fatalf("errno=%d err=%v\n", int(err.(*os.PathError).Err.(syscall.Errno)), err) } } Errno=8 is ERROR_NOT_ENOUGH_MEMORY. From http://goo.gl/nVQCR : >>> The WriteFile function may fail with ERROR_INVALID_USER_BUFFER or ERROR_NOT_ENOUGH_MEMORY whenever there are too many outstanding asynchronous I/O requests. <<< So, I guess, you need to use smaller buffer - see toStdout in my example. My modified program outputs: ... "Standard": true, "Root": "C:\\mingw\\go", "GoFiles": [ "unsafe.go" ] } 2012/03/26 11:37:59 errno=8 err=write /dev/stdout: Not enough storage is available to process this command. I am not sure what else we can do. So I am leaving this issue as WorkingAsIntended. Please, let us know, if you have better ideas. Alex |
After Go 1, I think we should look into writing to the console as a special case. Microsoft does not really believe in 'everything is a file'. We should accept that and use the console writing functions for writing to the console, instead of the generic file-writing function. Detecting the console this way would let us write small enough buffers (or whatever is provoking this) and would also let us use the W form of the function, so that the console would understand we're writing UTF-8. Labels changed: added priority-later, removed priority-triage. Owner changed to ---. Status changed to Accepted. |
Issue #3346 has been merged into this issue. |
fullung, I had similar problem to yours. I have created new issue https://golang.org/issue/3767, since Russ changed subject here. Alex |
http://golang.org/cl/6488044/ Status changed to Started. |
This issue was closed by revision 18601f8. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Attachments:
The text was updated successfully, but these errors were encountered: