2

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.

1 Answer 1

3

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
  • 1
    stdbuf is in debian coreutils: stdbuf --output=0 ./script > file Aug 13, 2015 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .