When I start the script test.py > test.log, the output is only written to the file test.log after the script has finished. How do I get the output to the test.log file while the script is running (live)?
I have tested without success:
./test.py > test.log
./test.py &> test.log
./test.py > test.log &
nohup python3 -u test.py > test.log 2>&1 &
works. But when multiple scripts are running, all tasks are named python3. This is unfavorable eg for the killall -9 command.
test.py
#!/usr/bin/python3
from time import sleep
for i in range(0,21):
print(i)
sleep(1)