Pass input to a command via golang

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?

You want the flag package. You can find documentation and examples here.

To pass input to a process that you spawned via exec.Command, see this example:

package main

import (

func main() {
	cmd := exec.Command("cat")
	stdin, err := cmd.StdinPipe()
	if err != nil {

	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 {

	fmt.Printf("%s\n", out)

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