Suppress STDOUT from a Ruby C extension
问题 I'm using the gem dep_selector in a project and can't figure out how to suppress the stdout from the library's C extensions. The code in question I want to suppress is here: https://github.com/RiotGames/knife_cookbook_dependencies/blob/master/lib/kcd/shelf.rb#L26 I tried this: real_stdout = $stdout $stdout = StringIO.new real_stderr = $stderr $stderr = StringIO.new puts "This gets suppressed correctly" selector.find_solution( ... ) # still prints to the terminal but I still get dep_selector