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?
I encountered the same problem. My code is basically the same as the author’s.
- For command programs written in golang, stdinpipe can work normally.
- 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