C language. Read from stdout

前端 未结 4 1869
抹茶落季
抹茶落季 2021-01-03 01:30

I have some troubles with a library function. I have to write some C code that uses a library function which prints on the screen its internal steps. I am not interested to

4条回答
  •  抹茶落季
    2021-01-03 01:49

    You should be able to open a pipe, dup the write end into stdout and then read from the read-end of the pipe, something like the following, with error checking:

    int fds[2];
    pipe(fds);
    dup2(fds[1], stdout);
    read(fds[0], buf, buf_sz);
    

提交回复
热议问题