On Jun 10, 2009, at 6:01 PM, Laurent Sansonetti wrote:
Hi Scott!
Here is a code snippet that hijacks stdout using an NSPipe. The idea is to first initialize the MacRuby VM (so that the standard descriptor objects are created), then use dup2(2), then evaluate your Ruby expressions.
<Code snipped for brevity> I appreciate you taking the time to type that in. This is basically the solution that I came up with. The problem with this solution (if I'm understanding what is going on correctly) is that the output that goes through the pipe is buffered while the output that usually goes to the controlling terminal is not. The result is that if the ruby script does not produce "enough" output, the reading end of the pipe never sees it. If the ruby code actually flushes the stream (or someone closes the pipe, which I gather also ends the stream) then the output makes it all the way, but if both my application and code on the Ruby side keep the pipe alive, it's possible for the ruby side to leave things in the pipe. Is it possible to create or set up the ends of the pipe to be un- buffered? Scott