os/exec: StdinPipe on Windows is not successful

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


Does this issue reproduce with the latest release?

package main

import (

func main() {
	command :="openconnect"
	param := []string{"","-u","test","--passwd-on-stdin"}
	cmd :=exec.Command(command,param...)
	stdin, err := cmd.StdinPipe()
	if err != nil {
	go func() {
		defer stdin.Close()
		io.WriteString(stdin, "123\n")
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	if err = cmd.Start(); err != nil { //Use start, not run
		fmt.Println("An error occured: ", err) //replace with logger, or anything you want

  • StdinPipe not work

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


What did you do?


I encountered the same problem. My code is basically the same as the author’s.

  1. For command programs written in golang, stdinpipe can work normally.
  2. BeamMP-Server.exe, stdinpipe does not work properly, but if I start it manually, I can enter commands normally.
    Download server

What did you expect to see?

stdinpipe work normally for BeamMP-Server.exe program.

What did you see instead?

  • no error
  • command no work
  • program stdout didn’t print everything

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.