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 关于#python#的问题:功能监听网页
    • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
    • ¥15 怎么让wx群机器人发送音乐
    • ¥15 fesafe材料库问题
    • ¥35 beats蓝牙耳机怎么查看日志
    • ¥15 Fluent齿轮搅油
    • ¥15 八爪鱼爬数据为什么自己停了
    • ¥15 交替优化波束形成和ris反射角使保密速率最大化
    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群