Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
719 views
in Technique[技术] by (71.8m points)

ruby on rails - Suppress Output in Rake Task db:schema:load

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

bundle exec rake db:schema:load

with the -s, -q, or even VERBOSE=false options makes no difference in the output; the same "create_table... add_index..." garbage that I don't want to see appears. I'm invoking this from inside a custom Rake task and I don't want the user to see all of this every time.

UPDATE:

I solved the problem with some guidance from @Deefour by using:

system "bundle exec rake db:schema:load -s RAILS_ENV=#{Rails.env} >NUL"

>NUL is for Windows machines, Unix-based can use > /dev/null.

rather than

Rake::Task['db:schema:load'].invoke

as I had been doing in my custom task. Note that this solution is specific to Windows machines. For Unix-based machines I imagine you should be able to use the accepted solution below.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...