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

go/src/bufio: fmt.Print files differently for windows/amd64 and linux/amd64 #30880

Closed
msmarino opened this issue Mar 16, 2019 · 2 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@msmarino
Copy link

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

$ go version
go1.12.1 windows/amd64

>ver

Microsoft Windows [Versión 10.0.17134.590]

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\tecop\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\Documents\Dev\Go
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\Documents\Dev\term\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\tecop\AppData\Local\Temp\go-build251247510=/tmp/go-build -gno-record-gcc-switches

What did you do?

package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os/exec"
	"time"
)

func main() {
	cmd := exec.Command("bash")

	in, _ := cmd.StdinPipe()
	out, _ := cmd.StdoutPipe()

	if err := cmd.Start(); err != nil {
		log.Fatal(err)
	}

	go func() {
		reader := bufio.NewReader(out)
		for {
			s, err := reader.ReadString('\n')
			if err != nil {
				fmt.Print("Done!")
				return
			}
			// log.Print(s)
			fmt.Print(s)
		}
	}()

	io.WriteString(in, "ls -lha\n")

	io.WriteString(in, "exit\n")

	time.Sleep(2 * time.Second)

	cmd.Wait()
}

What did you expect to see?

Output from go version
go1.12.1 linux/amd64

total 4.0K
drwxrwxrwx 1 marcos marcos 4.0K Mar 16 09:54 .
drwxrwxrwx 1 marcos marcos 4.0K Mar 15 22:28 ..
drwxrwxrwx 1 marcos marcos 4.0K Mar 15 22:48 .git
-rwxrwxrwx 1 marcos marcos   46 Mar 15 22:34 go.mod
-rwxrwxrwx 1 marcos marcos  576 Mar 16 09:46 main.go
Done!

What did you see instead?

total 4.0Ktotal 4.0K
drwxrwxrwx 1 marcos marcos 4.0K Mar 16 09:54 .drwxrwxrwx 1 marcos marcos 4.0K Mar 16 09:54 .
drwxrwxrwx 1 marcos marcos 4.0K Mar 15 22:28 ..drwxrwxrwx 1 marcos marcos 4.0K Mar 15 22:28 ..
drwxrwxrwx 1 marcos marcos 4.0K Mar 15 22:48 .gitdrwxrwxrwx 1 marcos marcos 4.0K Mar 15 22:48 .git
-rwxrwxrwx 1 marcos marcos   46 Mar 15 22:34 go.mod-rwxrwxrwx 1 marcos marcos   46 Mar 15 22:34 go.mod
-rwxrwxrwx 1 marcos marcos  576 Mar 16 09:46 main.go-rwxrwxrwx 1 marcos marcos  576 Mar 16 09:46 main.go
Done!

Sometimes some lines are output correctly and others not.
log.Print seem to always output correctly on Windows

@katiehockman katiehockman changed the title Intermitent Duplicated output from fmt.Print on Windows go/src/bufio: fmt.Print files differently for windows/amd64 and linux/amd64 Mar 19, 2019
@katiehockman
Copy link
Contributor

Looking at the expected vs. the actual output, I'm not sure that this is actually a bug, or just a difference in formatting depending on the OS that the program is being run against.

/cc @bradfitz @ianlancetaylor ?

@katiehockman katiehockman added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 19, 2019
@katiehockman katiehockman added this to the Unplanned milestone Mar 19, 2019
@bradfitz
Copy link
Contributor

I'm guessing that on Windows you probably have some '\r' bytes in there from bash messing up the output. This isn't really a Go issue, though. Try removing them before printing.

@golang golang locked and limited conversation to collaborators Mar 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants