How can I suppress a dump to STDOUT whenever I write to a file? The closest I could get to is using quietly
, but it still doesn't suppress output of the file's contents:
quietly do
puts "shhhh" # (suppressed)
File.write("filename.txt", "content") #=> "content"
end
EDIT: To make my question clearer, I'm not trying to suppress output to the file itself, but to the console. The File#write
above is writing the "content" to the file but is also echoing it back to the console.
Update
Here's the code in context:
namespace :export do
desc 'Export dictionary entries'
task :entries => :environment do |task|
# fetch entries, iterate over objects, concatenate string representation to "out"
filename = "entries.rb"
puts "Exporting entries to #{filename}..." # prints 1st
File.write(filename, out) # prints at the end
puts "Exported entries." # prints 2nd
end
end
I haven't overridden any IO method. But I have discovered that if I define another task like this (inspired from this answer):
task :call_entries => :environment do |task|
quietly do
Rake::Task['export:entries'].invoke
end
end
it actually suppresses all console output.