Redirect stdout pipe of child process in Go

后端 未结 3 920
长发绾君心
长发绾君心 2021-01-29 20:04

I\'m writing a program in Go that executes a server like program (also Go). Now I want to have the stdout of the child program in my terminal window where I started the parent p

3条回答
  •  情话喂你
    2021-01-29 20:13

    Now I want to have the stdout of the child program in my terminal window where I started the parent program.

    No need to mess with pipes or goroutines, this one is easy.

    func main() {
        // Replace `ls` (and its arguments) with something more interesting
        cmd := exec.Command("ls", "-l")
        cmd.Stdout = os.Stdout
        cmd.Stderr = os.Stderr
        cmd.Run()
    }
    

提交回复
热议问题