capturing stdout from so library
I have a package (rrdtool) that provides functionality through a shared
library and a Ruby interface (ruby-rrd) to it.
The problem is that one of the functions in the library (rrd_graph) only
returns data through a file descriptor; a file or standard output.
This is rather dumb in my opinion, but probably hard to fix. Also, a
a workaround seems easy:
@buffer = String.new
@buffer << string
oldout = $stdout
$stdout = StringBuffer.new
RRD.graph(... tons of options ...)
image = $stdout.buffer
$stdout = oldout
According to my theory, the StringBuffer object should have captured all
data sent to standard output while $stdout points to it, and image sould
contain a beautiful graph produced by RRD.graph.
However, what happens is that RRD.graph blatantly ignores the fact that
$stdout is redirected, and bangs its data to standard output anyway.
I assume this means that there's nothing I can do in Ruby to capture the
output to standard out from a library written in C. If this is true,
I have two options:
- Do something (but what?) in the Ruby/C interface
- Fix the library
Please tell me I'm wrong. :-)
|All times are GMT. The time now is 03:00 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.