我试图让一根管子通向cmd.ExtraFiles
我目前有错误说
cannot use cmdstdout (type io.ReadCloser) as type []byte in argument to pipeR.Read
cannot use cmdstdout (type io.ReadCloser) as type []byte in argument to fd3.Write
这是我到目前为止的 gocode
cmd2 = exec.Command("-i", "pipe:0", "-i", "pipe:1")
cmd1 := exec.Command("command", "-o", "-")
pipeR, pipeW, _ := os.Pipe()
cmd2.ExtraFiles = []*os.File{
pipeW,
}
cmd1.Start()
cmd1stdout, err := cmd1.StdoutPipe()
if err != nil {
log.Printf("pipeThruError: %v\n", err)
return err
}
fd3 := os.NewFile(3, "/proc/self/fd/3")
fd3.Write(cmd1stdout)
pipeR.Read(cmd1stdout)
pipeR.Close()
pipeW.Close()
fd3.Close()
cmd3 = exec.Command("command", "-o", "-")
stdin, stdinErr := cmd3.StdoutPipe()
if stdinErr != nil {
log.Printf("pipeThruFStdinErr: %v\n", stdinErr)
return stdinErr
}
cmd3.Start()
cmd2.Stdin = stdin
编辑:添加了完整范围目标是让 cmd2 通过 cmd3 接受输入Stdin,并让 cmd1 输出通过管道传输ExtraFiles
翻过高山走不出你
相关分类