Originally Posted by
lucas.lotr
Like i said, i know i could do that, i was just curious if there is a c equivalent to batch file`s ECHO which disables the displaying of messages.
You can temporarily dup() stdout or stderr, close them, then restore them again later:
Code:
#include <stdio.h>
#include <unistd.h>
int main(int argc, const char *argv[]) {
int stdout_copy = dup(1);
printf("hello world\n");
close(1);
printf("[suppressed]\n");
dup2(stdout_copy, 1);
close(stdout_copy);
printf("hello again\n");
return 0;
}
I don't know how portable that is because of unistd.h, but I'm sure all platforms must offer similar functionality.