How can I implement 'tee' programmatically in C?

后端 未结 5 593
情深已故
情深已故 2020-12-04 01:38

I\'m looking for a way in C to programmatically (ie, not using redirection from the command line) implement \'tee\' functionality such that my stdout goes to both stdout and

5条回答
  •  情深已故
    2020-12-04 02:03

    There's no trivial way of doing this in C. I suspect the easiest would be to call popen(3), with tee as the command and the desired log file as an arument, then dup2(2) the file descriptor of the newly-opened FILE* onto fd 1.

    But that looks kinda ugly and I must say that I have NOT tried this.

提交回复
热议问题