package main import ( "fmt" "io/ioutil" "os/exec" ) func main() { cmd := exec.Command("cat", "-n") input, err := ioutil.ReadFile("input.txt") if err != nil { panic(err) } cmd.Stdin = bytes.NewReader(input) output, err := cmd.Output() if err != nil { panic(err) } fmt.Println(string(output)) }
package main import ( "fmt" "os/exec" ) func main() { cmd := exec.Command("read", "-p", "What is your name? ", "name") cmd.Stdin = strings.NewReader("Jane\n") err := cmd.Run() if err != nil { panic(err) } fmt.Println("Hello, " + "Jane") }In this example, we use the `read` command to prompt the user for input. The `Stdin` field is used to write the user's input to the command. The `Run` function is used to start the command and wait for it to complete. The output of the command is not used, but we simply print a message to the console. Package Library: `os/exec`