-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
fmt: cannot read more than 254 characters in Windows when calling Fscanln #42551
Comments
Has it been confirmed if it's a Go issue? Input is truncated to a maximum of 254 characters whether typing or pasting. |
Same, stumbled upon this today when trying to paste a long authorization code into Wrapping var code string
in := bufio.NewReader(os.Stdin)
if _, err := fmt.Fscan(in, &code); err != nil {
log.Fatal(err)
} |
@reznik99, verifying that it is Go specific is actually quite simple. Try the following python script: s = input("input more than 254 characters:\n")
print("Received: " + s) You can execute this in your browser devtools to quickly generate a long string: copy("a".repeat(254) + "b")
|
This bug still exists in the latest stable version of Go language (1.22.9). |
Back when @karelorigin and I raised this I continued my research. The problem doesn't seem to be Go itself but the Windows console that stops reading input from the user after 254 bytes (256 if you add the required Not ideal but this seems to work on Windows 10: package main
import (
"fmt"
"golang.org/x/sys/windows"
)
const size = 1024
func main() {
stdin, err := windows.GetStdHandle(windows.STD_INPUT_HANDLE)
if err != nil {
panic(err)
}
buf := make([]uint16, size)
var read uint32
err = windows.ReadConsole(stdin, &buf[0], size, &read, nil)
if err != nil {
panic(err)
}
output := windows.UTF16ToString(buf[:read])
fmt.Print(output)
fmt.Printf("\nInput length: %d bytes (utf8 string)\n", len(output))
} Copy a large string such as this one and try it: $ python3 -c "print('A'*254 + 'B'*2 + 'C'*200)" | pbcopy
# AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
Input length: 458 bytes (utf8 string) That is 456 utf8 characters plus The Hope it helps @vault-thirteen 😄 |
@jimen0 , great job ! This is all cool, but ... ... all this should be done by the developers of Go language. Go's creators should incorporate all this into the standard library. End users of the language should not invent their own language upon the existing language. If people need to invent a second language upon the existing one, then something in the first language is wrong. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes. It also reproduces with current tip
go version devel +b34b0aaf69 Thu Nov 12 15:28:43 2020 +0000 darwin/amd64
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
On the Windows host, I type
A
character 257 times after running the program, then press enter key. The Go program reads them correctly.What did you see instead?
On the Windows host, I typed
A
character 257 times after running the program, then presed enter key. The Go program stdin froze after 254 characters.I don't really know if this is related to Go at all or an issue with Powershell itself, but I thought it was worth submitting an issue. This was initially discovered by @karelorigin.
Best regards,
Miguel
The text was updated successfully, but these errors were encountered: