How can I save a command output to a file in real-time?
For example, if my command is python log.py
where log.py
contains:
import time
print('testing')
time.sleep(100) # sleeping for 100 seconds
and if I save the output with python log.py | tee command.log
or python log.py > command.log
, the command.log
file typically won't contain the output of python log.py
, namely testing
, until it finishes executing. Instead, I don't want to have to wait ~100 seconds to be able to view testing
in command.log
.
unbuffer python log.py > command.log
, does it still matter that the C library buffers the output differently based on if the output goes to a terminal or to a file/pipe? – Franck Dernoncourt Jul 04 '18 at 20:38unbuffer
andstdbuf
basically override the default logic. Though in different ways, see:unbuffer
orstdbuf
for removing stdout buffering? – ilkkachu Jul 04 '18 at 20:41