dsjgk330337 2019-01-29 09:06
浏览 135

管道:1:错误的文件描述符

I saw via golang you can only do one Stdin so I'm trying to have two piped inputs into a cmd1.exec.Command(), one via Stdin and the other via ExtraFiles but the ExtraFiles pipe is giving pipe:1: Bad file descriptor when cmd1 tries to read it

cmd1 := exec.Command("command1", "-i", "pipe:0", "-i", "pipe:1", "more stuff")
cmd2 := exec.Command("command2", "-o", "-")
cmd3 := exec.Command("command3", "-o", "-")
stdin, stdinErr := cmd2.StdoutPipe()
if stdinErr != nil {
    return stdinErr
}
cmd2.Start()
cmd1.Stdin = stdin
pipeR, pipeW, _ := os.Pipe()
cmd1.ExtraFiles = []*os.File{pipeW}
extrastdin, extrastdinErr := cmd3.StdoutPipe()
if extrastdinErr != nil {
    return extrastdinErr
}
cmd3.Start()
fd3 := os.NewFile(3, "/proc/self/fd/3")
body, err := ioutil.ReadAll(extrastdin)
if err != nil {
    return err
}
fd3.Write(body)
defer pipeR.Close()
defer pipeW.Close()
defer fd3.Close()
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料