From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-05-13T18:50:54+09:00 Subject: Re: RCR for child execution On Tue, 13 May 2003 17:32:09 +0900, Brian Candler wrote: > On Tue, May 13, 2003 at 09:48:53AM +0900, Simon Strandgaard wrote: >> I want users of the editor to be able to use thier own favorite ruby >> snippets within the editor... *unmodified* ...they don't have to do popen >> or Open3 or other ackward things for executing their favorite scripts. >> All Ruby output should go to a text-buffer. > > You mean like irb? > > Maybe you should have a look at the source for FreeRIDE and see how it > handles this. I haven't installed it, but it sounds like exactly the sort of > integrated environment you're talking about, so they must have dealt with > the problem you have encountered. Yes like irb and FreeRIDE.. But again my environment is completely differnt. So it doesn't compare well. [snip code] > > What you have written cannot work: [snip issues about this pseudo code] its pseudo code.. And all those issues you pinpoint here is correct. But never the less I think its the solution :-) > But anyway, I wrote "in the general case", not "in the specific case of > system() and backtick" > > In the general case, your Ruby program could do lots of things which force > a direct output to stdout/stderr. Here is one small valid Ruby program: > > pid = fork do > exec("ls /nonexistent") > end > Process.waitpid(pid) > > How are you going to modify Ruby so that the output of those four lines are > captured in the sandbox? All "child-process" routines should parse rb_stdout to the children, in this case fork. I know I have only mentioned system&backquote before. Well all routines in Rubys Core which spawns children should do this. > Another example would be > > require 'ext/someobj' > a = Someobj.new.dosomething > > where ext/someobj is a C extension which writes directly to stdout. If your > editor environment is going to be general-purpose then it better handle that > case too. See, You are confusing (A) with (B) http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/71222 >> OK.. again assignment to stdout is illegal. freopen should be used instead. >> Admitted.. I havn't yet tried reopen'ing stdout/stderr :-) > > freopen only lets you associate the FD with a file. > > It would certainly be possible to do > STDOUT.reopen("/tmp/capture.out") > > before calling the snippet you are interested in. Then you can close it and > read the file. I cannot do this: redirect_output('elsewhere') { require 'snippet' } its not that simple.. The 'snippet' file contains a class which is instantiated within C/C++. Therefore the redirection must be permanente. > But that solution is specific to your problem. I don't think it warrants a > modification to Ruby, the general-purpose programming language, itself. you are reject this idea.. without understanding my problem first. Rejections is OK.. but only afterwards :-) -- Simon Strandgaard