问题
I want to associate pipe's write fd to the 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.
I understand, we can use freopen to redirect stdout to the file. I was hoping to get something similar to this.
回答1:
dup2(2) is probably the easiest way:
dup2(pfds[1], STDOUT_FILENO);
来源:https://stackoverflow.com/questions/18497401/how-to-change-the-fd-associated-with-the-stdin-file-descriptor