-1

I have a script that runs a python file. The script redirects python's print statement to a file constantly as it does its operations.

#!bin/bash
. venv/bin/activate
python3 mypythonfile.py > logfile.txt

When I run

cat logfile.txt

It seems to always take about 30 seconds to a minute to refresh its contents; in other words, I'm not able to see the information as it's being added to the logfile.txt.

Any suggestions?

I remember seeing something like a command that solved this years ago on the web however the results and forums usually mention how to look for files that are being written which is not what I am searching for :/

Any help and pointers would be greatly appreciated ;)

Edit: This question was marked as related to the following thread for some reason:

Python: subprocess.call, stdout to file, stderr to file, display stderr on screen in real time

While this is definitely helpful for other projects it could not at all be valued with the same consideration as the answers given here.

Thank you all for your comments.

Owlet
  • 47
  • 9

1 Answers1

3

If the content of the file is being updated while the process is running (and not all at once in the end), you can use the 'tail' command to see what's being written. You can use 'tail' with '-F' options which keep following the file even if it gets deleted and recreated (with the same name):

$ tail -F file1 [ /path/to/another/file ]
Inc0
  • 789
  • 1
  • 4
  • 12