redirect stdout

hello again!
i use dup2 to redirect stdout. I run what i want, now i want undo this redirection. how can i do that?

thanx in advance

Just close the file descriptor. You can then reopen for stdout/stderr whatever using dup2 again.

i did it, but i does not work!! can u help me?thanx anyway!

Could you show your code? We can't tell what's going wrong when we can't see what you're doing. Be sure to put it in code tags. like [ code ] [ /code ] but without the extra spaces.

i write this code to redirect stdout and stderr
dup2(fd2,STDOUT_FILENO);
dup2(fd1,STDERR_FILENO);//redirection of stdout and stderr in parent
close(fd2);close(fd1);

And what do you do to put them back?

i haven't manage to find a correct code yet.

Make a copy of the original ones...

int saved_fds[2];

saved_fds[0] = dup(STDOUT_FILENO);
saved_fds[1] = dup(STDERR_FILENO);

When you're done redirecting, you dup2 these back into place:

dup2(saved_fds[0],STDOUT_FILENO);
dup2(saved_fds[1],STDOUT_FILENO);