I am accessing a C function in Ruby through FFI. The function is called AllocTilts::summary.
I want the method to not print anything to STDOUT. However my temporary redirect of STDOUT is not working. Is there something else I can do?
puts 'test outside before' #prints successfully
File.open("/var/alloc_tilts/summary_dump", "w") do |out|
stdout, $stdout = $stdout, out
puts 'test inside' #doesn't print to STDOUT as expected
AllocTilts.summary(2012, 2011) #prints undesired stuff to STDOUT
$stdout = stdout
end
puts 'test outside after' #prints successfully
How do
AllocTilts.summarywrite to stdout? If it usesprintfand you do not have access to its source code there is nothing you can do (short of calling libcdup).The way ruby writes to
$stdoutrather than the real stdout, isYou should use similar code to generate output inside
AllocTilts.summary.