0
我正在使用以下代碼將我的打印語句重定向到文本文件中。重定向打印到日誌文件,也在子進程中
old_stdout = sys.stdout
log_file = open("message.log","w")
sys.stdout = log_file
print "this will be written to message.log"
subprocess.call("iPython.exe", "script.py") #subprocesses here take this form
sys.stdout = old_stdout
log_file.close()
我的問題是,這似乎並不適用於子過程。 「script.py」中的打印語句不會出現在「message.log」中。我該如何做到這一點?
有一個特定的日誌記錄庫可能是更好的選擇 - https://docs.python.org/2/library/logging.html – thefragileomen 2014-11-05 03:01:55