Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想将管道的写入 fd 与标准输出相关联。
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 将标准输出重定向到文件。我希望得到类似的东西。
dup2(2)可能是最简单的方法:
dup2(2)
dup2(pfds[1], STDOUT_FILENO);