Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Redirection of python script output to file not working

I have a simple python file on a Linux VM

import time
while True:
    print("test")
    time.sleep(10)

which I start with

python test.py  > test.log

but even after a longer time that file is empty

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

-rwxrwx--- 1 root vboxsf      0 Sep 29 07:57 test.log

Is the output cached or something? How can I make the output to go into the file right away?

I am pretty sure I forgot something very easy…

>Solution :

change print like below

print("test", flush=True)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading