如何在Golang程序中以编程方式向os.stdin输入字符

I want to automatically provide input to a command in the bash terminal.

Is it possible to programmatically enter a "yes" after than ssh prompt? Here is a script representing the idea.

package main
import (
    "bytes"
    "io"
    "os"
    "fmt"
    "os/exec"
 )
func main() {
    c1 := exec.Command("ssh","root@172.30.0.77")
    r, w := io.Pipe()
    c1.Stdout = w
    c1.Stdin = r
    c1.Start()
    var b bytes.Buffer
    b.Write([]byte("yes"))
    fmt.Fprintf(&b, "
")
    b.WriteTo(os.Stdin)
    c1.Wait()
    w.Close()

 }

# go run login.go 
yes
The authenticity of host '172.30.0.77 (172.30.0.77)' can't be established.
RSA key fingerprint is 13:46:96:ff:ab:12:76:0e:24:6e:3e:7a:ee:c0:81:af.
Are you sure you want to continue connecting (yes/no)? 

This is wrong on so many levels, but let me pick just the worst one.

Many programs, usually for very good reasons, try hard to ensure that they're interacting with a human, not a redirected input, here doc etc.

Attempts to subvert those very good reasons is a horrible idea and IMHO a big no-no.

If you want to interact programmatically with the ssh protocol, use a library (a package in case of Go), not a client binary.