Printing to screen in a rake task

2019-02-07 01:53发布

问题:

I have a long running rake task. Every now and then I print an update to the screen to let me know how far along the task has come.

puts "Almost there..."

My problem is all the puts statements seem to buffer somewhere and won't print to the screen until after the task is complete. At which point, they will be printed all at once.

Is there some way to force them to print as the task is running?

回答1:

STDOUT.sync = true


回答2:

May be you could flush the standart output:

STDOUT.flush