0

I am running a Python script on Linux bash. The script prints output from time to time. I want to:

  • redirect script output to file
  • run it in background
  • have ability to tail -f the results in the file while the script is running

I want to use tail -f only from time to time to monitor progress in some long process. I don't know why but after I redirect output I see no content in the file while the process is still running. Full content appears in the file after Python script ends.

Alireza
  • 2,319
  • 2
  • 23
  • 35
Jakub W
  • 23
  • 4
  • 2
    So....do that. What's the question? Are you just looking for : `script > file & tail -f file`? – William Pursell Jan 04 '20 at 14:01
  • 1
    Or perhaps buffering is an issue: https://unix.stackexchange.com/questions/25372/turn-off-buffering-in-pipe – William Pursell Jan 04 '20 at 14:07
  • I want to use tail -f only from time to time to monitor progress in some long process. I don't know why but after I redirect output I see no content in file while process is still running. Full content appears in file after Python script ends. – Jakub W Jan 04 '20 at 14:07
  • `man python`: _`-u` Force stdin, stdout and stderr to be totally unbuffered._ Would that work? – James Brown Jan 04 '20 at 14:25
  • 3
    Buffering was my problem. I applied this solution: https://unix.stackexchange.com/a/25375. ```python3 -u script.py``` solution also works. – Jakub W Jan 04 '20 at 14:25
  • Related: http://www.pixelbeat.org/programming/stdio_buffering/ – kvantour Jan 04 '20 at 16:40
  • Other possible duplicate: https://stackoverflow.com/q/3332045/8344060 – kvantour Jan 04 '20 at 16:48

0 Answers0