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 |
I umm only read the last line.....
try just running your command and pipe it to a file at the beginning of the run eg file to run > /home/yourname/myoutput.txt > creates file "myoutput.txt" >> would append to a file if you needed to do several runs? |
I want to do it from the C program and not by using the redirection operator on command line as I want log some output on the screen and some in the file.
// Rahul |
open /dev/tty, and it should go to your keyboard/screen
|
All times are GMT -5. The time now is 04:33 PM. |