I would like to redirect the output of a script (Python or any other kind) to a file. Easy to do with > or >>.

But with these two the output seems to be written in the file only once the script returns. Is there a way to write the output in the file as soon as it is redirected from the standard output ? Kind of like a log file that can be accessed to read the last steps of the script.

Thanks in advance.


Many programs will buffer their output, or the shell will buffer it, so it isn't necessarily waiting until the script completes, but until the buffer (often 4096 bytes) is full. Within the script you can manually flush the buffer each time you want. Alternately, you could try an external package like unbuffer.

  • 1
    stdbuf is in debian coreutils: stdbuf --output=0 ./script > file – glenn jackman Aug 13 '15 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.