Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Re-Direct cerr...

Status
Not open for further replies.

mbaranski

Programmer
Nov 3, 2000
421
0
0
US
I've got a program that does some stuff, and has logging information being printed to one file, other stuff going to cout, and errors going to cerr. I want to re-direct cerr to a log file, without messing up anything else. Basically, if there is an option specified in the config file, write cerr to ./error.log, otherwise, write it to /dev/null or whatever. How do I do this? Can I just open a fstream object and assing cerr to it? I'd appreciate an example (simple, of course)

Thanks
Mike B.

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
You could do it at the prompt in this way:
program_name 2> error.log

Is it enough?
 
No, that redirects standard out, which I'm using for mysql output. I'm calling the program like:

./import | mysql -f

Which imports a database by connectiing over a network and pushing the data out to standard out in the mysql file format. I am printing logging and error messages via cerr, instead of cout, which is currently pointed at the terminial screren, even when piping or re-directing. I need to open an ostream or something and tell cout to use it to write to a file.

Thanks anyway.

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top