![]() |
Redirecting Console Output
I need to redirect all console output (including error messages) to a log file. There are several reasons why I would have to go out of my way to change each print statement to a call to a function. It would be much easier if there's some support in the sys library for just that?
Any helpful info? |
Quote:
:
import sysAnother alternative would be to import logging and actually log things properly rather than using prints. -T. |
You generally do this from the command line. Not sure if this is the same with windows (doubtful) but under Linux (with BASH) you generally do
:
python foo.py > logfile.txt 2>&1If you're writing to stderr from your Python program then you want to just set sys.stderr to sys.stdout at the top of your source file, which will effectively 'redirect' everything to STDOUT. |
The "> file.ex" thing does work in windows as does the "< input.ex" for providing automatic input. Didnt know about the "2>&1" ... where abouts can I find some documentation on it, Cerulean?
|
| All times are GMT -5. The time now is 2:59 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC