How can I use fprintf and write to a pipe?

后端 未结 1 816
名媛妹妹
名媛妹妹 2021-02-15 17:14

I created a pipe and I used dup2() to overwrite streams 1 & 2 (stdout & stderr) into those pipes.

Now I wish to use fprintf to write to stream 1 or 2, but my pro

1条回答
  •  执念已碎
    2021-02-15 17:48

    If you have a file descriptor and want a FILE*, you can use fdopen

    FILE *fdopen(int fd, const char *mode);
    

    fdopen is a Posix function and documented in man fdopen. To do the reverse you can use fileno

    0 讨论(0)
提交回复
热议问题