Skip to content

os/exec: StdinPipe on Windows is not successful #63198

@zplzpl

Description

@zplzpl

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

1.18.2

Does this issue reproduce with the latest release?

package main

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

func main() {
	command :="openconnect"
	param := []string{"https://192.168.0.100:1443","-u","test","--passwd-on-stdin"}
	cmd :=exec.Command(command,param...)
	stdin, err := cmd.StdinPipe()
	if err != nil {
		log.Fatal(err)
	}
	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
	}
	cmd.Wait()

}
  • StdinPipe not work

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

windows

What did you do?

#19452

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.
    https://beammp.com/
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeOS-WindowsWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions