appears to have solved the issue with our code printing stderrs

This commit is contained in:
cktricky
2013-10-27 22:38:38 -04:00
parent 11480ac853
commit 86035a1cbd
2 changed files with 15 additions and 1 deletions
+1
View File
@@ -1,2 +1,3 @@
module BenefitFormsHelper
end
+14 -1
View File
@@ -12,7 +12,7 @@ class Benefits < ActiveRecord::Base
def self.make_backup(file, data_path, full_file_name)
if File.exists?(full_file_name)
system("cp #{full_file_name} #{data_path}/bak#{Time.now.to_i}_#{file.original_filename}")
silence_streams(STDERR) { system("cp #{full_file_name} #{data_path}/bak#{Time.now.to_i}_#{file.original_filename}") }
end
end
@@ -21,5 +21,18 @@ class Benefits < ActiveRecord::Base
FileUtils.cp "#{full_file_name}", "#{data_path}/bak#{Time.now.to_i}_#{file.original_filename}"
end
=end
def self.silence_streams(*streams)
on_hold = streams.collect { |stream| stream.dup }
streams.each do |stream|
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
stream.sync = true
end
yield
ensure
streams.each_with_index do |stream, i|
stream.reopen(on_hold[i])
end
end
end