Showing posts with label io redirection. Show all posts
Showing posts with label io redirection. Show all posts

17 September 2010

Caution when redirecting stdin/stdout/stderr in C

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.

C sample code - Program Using Pipes and IO redirection


Posted from Diigo. The rest of my favorite links are here.