Reputation: 808
Hello I am writing a program in C. I start it like that after compilation.
/a.out <source.txt >output
I want all messages to be printed to the output.txt. However I would like to send errors to the console, not to the file. The problem is when i use this statement in my code:
freopen( "errors.txt", "w", stderr );
fprintf (stderr, "%s\n", s);
All Erros are also printed to the output.txt file not to errors.txt I would be grateful for any help.
Upvotes: 2
Views: 5547
Reputation: 1479
By default the stdout
and stderr
are together routed to your console. However you can redirect the error stream to a file with the help of the following form of your command line: ./a.out 2>logfile.log. In that case the stdout
will still come to the console, but stderr
will go to the file.
Upvotes: 1