Skip to content

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

Closed
@msmarino

Description

@msmarino

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

Activity

changed the title [-]Intermitent Duplicated output from fmt.Print on Windows[/-] [+]go/src/bufio: fmt.Print files differently for windows/amd64 and linux/amd64[/+] on Mar 19, 2019
katiehockman

katiehockman commented on Mar 19, 2019

@katiehockman
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 ?

added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Mar 19, 2019
added this to the Unplanned milestone on Mar 19, 2019
bradfitz

bradfitz commented on Mar 19, 2019

@bradfitz
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.

locked and limited conversation to collaborators on Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bradfitz@msmarino@gopherbot@katiehockman

        Issue actions

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