Reopen the stdout and stderr
Hello All,
Is it possible to reopen the stdout and stderr descriptos after closing them.
For e.g.
int main()
{
FILE *ftemp = fopen("/tmp/one.txt", "w+");
int fd = fileno(ftemp);
close(1); /* close the stdout associated with screen */
close(2); /* close the stderr associated with screen */
dup(fd); /* one.txt is new stdout for the process */
dup(fd); /* one.txt is new stderr for the process */
close(1); /* close the one.txt stdout */
close(2); /* close the one.txt stderr */
/*
Now here is it possible to associate and 1 and 2 file descriptors to screen?
*/
return 0;
}
This I need because some part of program output (and error) I want to redirect it to a file and other on a screen.
Thanks,
// Rahul
|