Printing to screen in a rake task

2019-02-07 01:54发布

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?

2条回答
别忘想泡老子
2楼-- · 2019-02-07 02:30
STDOUT.sync = true
查看更多
Viruses.
3楼-- · 2019-02-07 02:32

May be you could flush the standart output:

STDOUT.flush

查看更多
登录 后发表回答