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 use fmt.Println in Read function produce twice output #28263

Closed
CodeisCold opened this issue Oct 18, 2018 · 3 comments
Closed

why use fmt.Println in Read function produce twice output #28263

CodeisCold opened this issue Oct 18, 2018 · 3 comments

Comments

@CodeisCold
Copy link

Please answer these questions before submitting your issue. Thanks!

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

go version go1.11 linux/amd64

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/vagrant/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/vagrant/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build800851283=/tmp/go-build"

What did you do?

code:
https://play.golang.org/p/BJeMXgI2Kw1

What did you expect to see?

test
azAZLbh penpxrq gur pbqr!

What did you see instead?

test
azAZLbh penpxrq gur pbqr!test

@CodeisCold
Copy link
Author

It also happen when change stdout to stderr or bytes.Buffer

@ianlancetaylor
Copy link
Contributor

io.Copy calls Read once to get some data, and copies that to os.Stdout. Then it calls Read again to see if there is any more data. The second call returns an error of io.EOF, so io.Copy stops.

This is working as expected.

@CodeisCold
Copy link
Author

Thanks

@golang golang locked and limited conversation to collaborators Oct 18, 2019
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

3 participants