简体   繁体   中英

Logging process output to file in real time

I have a python script running on startup in the background. Its print commands do not come through to the bash console as they do when calling the script manually with eg python script.py . Output and errors can be redirected to file by calling python script.py > log.txt 2>&1 . But after startup, as the script runs, I can see the log file but it has zero size, so is presumably waiting for the script to end. Calling it with cat returns nothing. I've tried using append >> instead with no luck.

Is there any way to make the output happen in real time, so it can be viewed?

您的输出正在缓冲中,因此请在Python脚本中刷新它,以确保显示结果:

sys.stdout.flush()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM