Hello i want to pass input to a command.
actually, i want to execute a command which asks input.
like :
update_euql --kri
after running , this command will show :
updating the euql via kri command. Do You want to try another method [y/n]
i want to pass n
to this command
how can i do it in golang?
skillian
(Sean Killian)
June 25, 2021, 5:59pm
2
You want the flag
package. You can find documentation and examples here .
j-forster
(Johann Forster)
June 28, 2021, 6:54am
3
To pass input to a process that you spawned via exec.Command
, see this example:
https://golang.org/pkg/os/exec/#example_Cmd_StdinPipe
package main
import (
"fmt"
"io"
"log"
"os/exec"
)
func main() {
cmd := exec.Command("cat")
stdin, err := cmd.StdinPipe()
if err != nil {
log.Fatal(err)
}
go func() {
defer stdin.Close()
io.WriteString(stdin, "values written to stdin are passed to cmd's standard input")
}()
out, err := cmd.CombinedOutput()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", out)
}
system
(system)
Closed
September 26, 2021, 6:54am
4
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.