我在代码中使用 python-daemon,其中包含 print 语句。我想将它们发送到一个文件,所以我运行了以下命令:
python server.py >> log.out
然而什么也进不去log.out
.
谁能告诉我我需要做什么?
Thanks.
DaemonContext 对象允许在创建对象时重定向 stdout/stderr/stdin。例如:
import os
import daemon
if __name__ == '__main__':
here = os.path.dirname(os.path.abspath(__file__))
out = open('checking_print.log', 'w+')
with daemon.DaemonContext(working_directory=here, stdout=out):
for i in range(1, 1000):
print('Counting ... %s' % i)
你应该能够cat checking_print.log
并查看打印语句的输出。
DaemonContext 对象的一个很好的参考是PEP 3143 http://www.python.org/dev/peps/pep-3143/.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)