Redirecting the output of a child process

前端 未结 2 870
南旧
南旧 2021-01-22 11:42

There are several ways of redirecting the output of a child process:

  1. using freopen(3)
  2. using dup(3)
  3. using popen(3)
2条回答
  •  情歌与酒
    2021-01-22 12:33

    I would expect to find dup2() used mainly.

    Neither popen() nor freopen() is designed to handle redirections such as 3>&7. Up to a point, dup() could be used, but the 3>&7 example shows where dup() starts to creak; you'd have to ensure that file descriptors 4, 5, and 6 are open (and 7 is not) before it would handle what dup2() would do without fuss.

提交回复
热议问题