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
x/sys/windows: use windows.ReadFile
read chinese failed
#54389
Comments
In your demo code, you read a slice of bytes from the console, then convert to a string:
which seems to assume that those bytes are UTF-8 encoded-- are you sure this is the case? If some other encoding is being used, this would explain why you are seeing garbage output. Example https://go.dev/play/p/_A2_ideqH8H
|
I'm sure it's utf-8 @thanm |
@thanm You can take a look at this gif, it's what I just ran with my code |
I can't read your GIF -- please post in text format. Thanks. |
ok,this is code https://go.dev/play/p/e6nVtwf7GLH . input
input
|
Thanks. In that case, I don't have a good idea why ReadFile would be returning [186 195 13 10], that doesn't have anything to do with '好' as far as I can tell. Have you tried writing '好' to a regular file and then reading that? |
Ok,I wrote another test code to read data from regular file and console respectively, https://go.dev/play/p/T1qkWs1DOsF output:
Looks like there is a problem with reading from the console |
Thanks for that. @golang/runtime @alexbrainman |
It seems package main
import (
"fmt"
"golang.org/x/text/encoding/simplifiedchinese"
)
func main() {
decodeBytes, err := simplifiedchinese.GB18030.NewDecoder().Bytes([]byte{186, 195, 13, 10})
if err != nil {
panic(err)
}
str := string(decodeBytes)
fmt.Printf("%q", str)
} Output:
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, upgread to
v0.0.0-20220808155132-1c4a2a72c664
reproduceWhat operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
read Chinese from console
https://go.dev/play/p/e3o6XINrBIv
demo code
What did you expect to see?
can parse Chinese correctly
What did you see instead?
there is no correct parsing of Chinese now
The text was updated successfully, but these errors were encountered: