You must save the original preopened file descriptors using
dup(). You then use dup2(), open() to do IO redirection. After done with IO redirection, you need to restore default stdin/stdout/stderr using sdup2() again, otherwise you program cannot interact with STDIO properly as it could before IO redirection! The previous article on this blog shows a good code example on how to do that.
No comments:
Post a Comment