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

why can't get input line from stdin when this line end with EOF #33590

Closed
hwhe opened this issue Aug 12, 2019 · 2 comments

Comments

@hwhe
Copy link

commented Aug 12, 2019

What version of Go are you using (go version)?

$ go version
go version go1.9.7 windows/amd64

Does this issue reproduce with the latest release?

func main() {
reader := bufio.NewReader(os.Stdin)
inputBuffer, err := reader.ReadString('\n')
if err != nil && err != io.EOF {
fmt.Println(err.Error())
return
}

inputBuffer = strings.TrimRight(inputBuffer, "\r\n")
inputStrings := strings.Split(inputBuffer, " ")
fmt.Println(inputStrings)

}

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

when i input 123 and Ctrl+D, can't get the 123?

123^D
[]

What did you expect to see?

Ctrl+D is EOF, i should got the 123

What did you see instead?

i cat't got the 123
i wonder kown the reason

@dmitshur

This comment has been minimized.

Copy link
Member

commented Aug 12, 2019

It should work, it likely has to do with how your terminal interprets Ctrl+D presses. You might have to press it twice, or do Ctrl+D followed by Enter. See https://superuser.com/a/169057 for more about those shortcuts and how they differ between terminals.

That said, our issue tracker is not the best medium for questions. More people will see your question, and you will get better answers, if you ask on a forum rather than on the issue tracker. See https://golang.org/wiki/Questions.

@dmitshur dmitshur added the Question label Aug 12, 2019

@andybons

This comment has been minimized.

Copy link
Member

commented Aug 12, 2019

Hi there,
We have decided that our experiment to allow questions on the issue tracker has not had the outcome we desired, so I am closing this issue. I'm sorry that we can't answer your question here.

There are many other methods to get help if you're still curious:

Thanks

@andybons andybons closed this Aug 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.