1

パイプの書き込み 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 を使用して stdout をファイルにリダイレクトできることは理解しています。私はこれに似たものを手に入れたいと思っていました。

4

1 に答える 1

3

dup2(2)おそらく最も簡単な方法です:

dup2(pfds[1], STDOUT_FILENO);
于 2013-08-28T20:17:50.570 に答える