Search code examples
ruby-on-railsbashgreppiperake

how to properly pipe the output of a "bundle exec rake ..." command


I have a rake take I run like this

be rake fix_pf_administrator_pct_assets

The rake task is part of a larger rails app.

There's a loop in the code, and a sleep 1, so I get a very "real time" output of the script.

However, if I do this

be rake fix_pf_administrator_pct_assets | grep mydebugprint

I have to wait till the whole script finishes before seeing the results.

How can I have real-time output of the script, while being able to grep for interesting lines.


Solution

  • If you're on a systetm with GNU coreutils, you can force the output of the rake task to be line buffered: (assumes "be" is not a shell alias but a command)

    stdbuf --output=L be rake fix_pf_administrator_pct_assets | grep mydebugprint
    

    stdbuf(1) man page