There are several ways of redirecting the output of a child process:
freopen(3)
dup(3)
popen(3)
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.