Suppress Output in Rake Task db:schema:load

后端 未结 2 458
走了就别回头了
走了就别回头了 2020-12-18 00:11

How can you suppress the output of db:load:schema? Running

bundle exec rake db:schema:load

with the -s, -q, or ev

相关标签:
2条回答
  • 2020-12-18 00:44

    Here is a cleaner solution that works cross-system:

    silence_stream(STDOUT) do
      # anything written to STDOUT here will be silenced
      Rake::Task["db:schema:load"].invoke
    end
    

    also

    quietly do
      # anything written to STDOUT or STDERR here will be silenced
      Rake::Task["db:schema:load"].invoke
    end
    

    I prefer silence_stream(STDOUT) toquietly because it will still allow error messages written to STDERR to be shown, which will be helpful when the rake command starts to act up.

    References: silence_stream, silence_warnings, & quietly

    0 讨论(0)
  • 2020-12-18 00:52

    Instead of calling the task with Rake::Task['...'].invoke, you can run the command in a subshell, redirecting output to /dev/null.

    system "bundle exec rake db:schema:load > /dev/null 2>&1"
    
    0 讨论(0)
提交回复
热议问题