Suppressing output in a Rake db: schema: load task

How can you suppress db: load: schema output? Launch

bundle exec rake db:schema:load 

with options -s , -q or even VERBOSE=false does not affect the output; the same "create_table ... add_index ..." trash appears that I do not want to see. I am invoking this from within the Rake user task, and I do not want the user to see all this every time.

UPDATE:

I solved the problem with some recommendations from @Deefour using:

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

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

but not

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

as I did in my custom task. Please note that this solution applies to Windows machines. For Unix-based computers, I assume that you can use the solution below.

+7
windows ruby-on-rails ruby-on-rails-3 rake
Aug 22 '12 at 18:44
source share
2 answers

Here is a cleaner solution that works in a cross-system:

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

and

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

I prefer from silence_stream(STDOUT) to quietly , because it will display error messages written to STDERR , which will be useful when the rake command takes effect.

References: silence_stream , silence_warnings , and quietly

+25
Dec 31 '14 at 18:02
source share

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

 system "bundle exec rake db:schema:load > /dev/null 2>&1" 
+3
Aug 22 2018-12-12T00:
source share



All Articles