Skip to content
Advertisement

How to get stdout/stderr in logfiles immediately?

To run some Python program I use the following bash script:

python3 /MyProg.py 0>/dev/null 1>>output_log_file 2>error_log_file

However I can get information after the prog is terminated only. When program is running there are not any data in these files.

Can I override this behavior to get log data immediately? My OS is Raspbian.

Advertisement

Answer

I suspect the program needs to flush stdout and stderr periodically, via

import sys
sys.stdout.flush()
sys.stderr.flush()
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement