我有python脚本
test.py
当我通过命令面板在Linux中运行时,它会显示日志(脚本正在做什么(
python test.py
但当我以这种方式运行它时,在脚本完成之前,我无法看到日志文件:
nohup python test.py 1> logifle.log 2>&1 &
在脚本运行期间,如何查看logfile.log中的日志?
使用-u
标志;来自python --help
:
-u : force the stdout and stderr streams to be unbuffered;
this option has no effect on stdin; also PYTHONUNBUFFERED=x
需要这样做:
nohup python -u test.py 1> logifle.log 2>&1 &