Re: [MacRuby-devel] Low-ish level MacRuby interaction
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
Hi Scott, Have you considered setting sync to true in your ruby code: STDOUT.sync = true This will tell stdout to flush after every write/puts etc. - Jude 2009/6/11 Scott Thompson <easco@mac.com>
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 _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Have you considered setting sync to true in your ruby code:
STDOUT.sync = true This will tell stdout to flush after every write/puts etc.
I was not aware of that option, but it sounds like just what I need. I will give it a try. Thank you very much! Scott
Have you considered setting sync to true in your ruby code:
STDOUT.sync = true This will tell stdout to flush after every write/puts etc.
I was not aware of that option, but it sounds like just what I need. I will give it a try. Thank you very much!
Oh noes! Busted. I had to switch to the experimental branch for reasons that I can't discuss (NDA you know) and found that the implementation of IO is... perhaps not as complete as one might like on that branch :-D Oh well. I can try again later, after I get home. Thanks for your suggestions! Scott
participants (2)
-
Jude Sutton
-
Scott Thompson