go: os/exec: Pipe of command's stdout to network connection not working on windows
What did you do?
I’m trying to pipe the output of a program to a network connection. The code below works on Linux/android/osx:
package main
import (
"log"
"net"
"os"
"os/exec"
)
func main() {
conn, err := net.Dial("tcp", "localhost:8089")
if err != nil {
log.Fatal(err)
}
defer func() {
err := conn.Close()
if err != nil {
log.Fatal(err)
}
}()
cmd := exec.Command("echo", "hello world")
cmd.Stdout = conn
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
err = cmd.Run()
if err != nil {
log.Fatal(err)
}
}
What did you expect to see?
I expect the string “hello world” sent to tcp://localhost:8089, as works in linux,
What did you see instead?
Nothing is sent.
System details
go version go1.9.1 windows/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=".exe"
GOHOSTARCH="amd64"
GOHOSTOS="windows"
GOOS="windows"
GOPATH="C:\Users\Tiago\go"
GORACE=""
GOROOT="C:\Go"
GOTOOLDIR="C:\Go\pkg\tool\windows_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-m64 -mthreads -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOROOT/bin/go version: go version go1.9.1 windows/amd64
GOROOT/bin/go tool compile -V: compile version go1.9.1
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19 (13 by maintainers)
That should probably work, thank you very much. @ianlancetaylor you could work at Microsoft now. I will report back with my findings.
Alex