Skip to content

os/exec: O_APPEND *os.File as Cmd.Stdout results in "write error: Bad file descriptor" on Windows #27638

@mvdan

Description

@mvdan

Beware that I haven't used Windows in more than seven years, and I have never developed on it. So I might have missed something obvious, or this may be a duplicate - apologies if so.

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

go version go1.11 windows/amd64

Does this issue reproduce with the latest release?

Yes.

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

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\appveyor\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=c:\gopath
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=
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\appveyor\AppData\Local\Temp\1\go-build205334498=/tmp/go-build -gno-record-gcc-switches

What did you do?

Try to feed a write-append os.File as Cmd.Stdout:

https://play.golang.org/p/VsK_0Er5WiR

What did you expect to see?

What I see on go version devel +b2fcfc1a50 Wed Sep 12 07:50:10 2018 +0000 linux/amd64:

$ go run reproduce_bug.go
$ cat f
foobarbaz

What did you see instead?

go run reproduce_bug.go
echo: write error: Bad file descriptor
panic: exit status 1
goroutine 1 [running]:
main.main()
	C:/gopath/src/mvdan.cc/sh/reproduce_bug.go:35 +0x32a
exit status 2

I'm reproducing this via AppVeyor CI, since I don't have a Windows machine at hand: https://ci.appveyor.com/project/mvdan/sh/build/312

This is a minimized case after a Windows user reported a bug in a project of mine: mvdan/sh#289

I carefully read both the os and os/exec godoc pages, and I couldn't find anything that seemed to imply this wouldn't work. I do see ExtraFiles is not supported on Windows., but I'm not using that myself. And a non-append file works, as far as I can tell.

In the original issue, the user shows how manually setting up the file for appending via f.Seek(0, 2) instead of O_APPEND does the trick. So it seems to me like what I'm doing should be somehow possible.

/cc @alexbrainman @antylama

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.OS-Windows

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions