- I am running a Ruby gem which relies on a C extension (not a call to system).
- The C code makes several calls to printf.
- I want to silence the output of these calls.
- Changing Ruby’s STDOUT (example) or STDERR does not prevent the text from being output.
Is it possible to do this without modifying the C code? If so, how?
Someone originally commented on my post suggesting to use IO.reopen. This worked for me. The person has unfortunately since deleted his/her comment, so I’m posting the more detailed function I used in the end:
Usage: