How to flush stdout

I have a Julia script that has a bunch of println statements interleaved some heavy computation functions. I typically run such scripts, redirect to a file, and then do tail -f to see what’s going on. It appears that the output is buffered. I tried to make it flush but it doesn’t work… What’s the right way to do this?

My logging function:

log(x...) = println(now(), " ", join(x, " ")...); flush(STDOUT)
2 Likes

This definition doesn’t do what you probably want it to do. It’s equivalent to this:

log(x...) = println(now(), " ", join(x, " ")...)

flush(STDOUT)

You probably want this:

function log(x...)
    println(now(), " ", join(x, " ")...)
    flush(STDOUT)
end
4 Likes

Thanks for correcting my sloppiness :slight_smile:

Now the solution is:

flush(stdout)

(with lowercase letters)

22 Likes