如何更改与stdin文件描述符关联的fd?

时间:2013-08-28 20:16:29

标签: linux ipc

我想将pipe的写入fd与stdout相关联。

int pfds[2];
char buf[30];

if (pipe(pfds) == -1) {
    perror("pipe");
    exit(1);
}

I want to associate pfd[1] to the stdout of the process. 

据我所知,我们可以使用freopen将stdout重定向到该文件。我希望得到类似的东西。

1 个答案:

答案 0 :(得分:3)

dup2(2)可能是最简单的方法:

dup2(pfds[1], STDOUT_FILENO);
相关问题