If I read your post correctly, you want to direct stderr messages to a file, for a temporary amount of time, and then restore everything to 'normal' so that future stderr-directed messages are displayed on the console, as they normally would.
Well, here's some 'cheesy' code that does this, and it should be portable:
Code:
#include <stdio.h>
int main(void)
{
FILE* errFile = fopen("myErrors", "w+");
FILE* save_stderr = stderr;
stderr = errFile;
// this will go to the file
fprintf(stderr, "This is my first error message.\n");
fclose(errFile);
stderr = save_stderr;
// this will go to the terminal
fprintf(stderr, "This is my second error message.\n");
return 0;
}
Bookmarks