最佳答案
Via Brad Fitzpatrick, here's one way to do it .您可以将第二个命令的 Stdin
属性重新分配给第一个命令的 stdout
writer。
ls := exec.Command("ls")
wc := exec.Command("wc")
lsOut, _ := ls.StdoutPipe()
ls.Start()
wc.Stdin = lsOut
o, _ := wc.Output()
fmt.Println(string(o))
关于go - 使用 golang 的 os/exec,如何将标准输出从一个进程复制到另一个进程的标准输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31643678/