From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-05-08T07:26:54+09:00 Subject: Re: capture output On Thu, 08 May 2003 07:58:18 +0900, Brian Candler wrote: > On Wed, May 07, 2003 at 10:58:38PM +0900, Simon Strandgaard wrote: >> [snip popen talk] >> >> Sorry.. I never thought it would be that hard to explain >> my problem :-) >> >> >> I embed ruby into C++. The "void main" is located in the frontend. >> Right now everything is running in the same process. >> >> User supplyed ruby-code is executed in the same process... >> its NOT executed as a child-process, thus popen3 is not possible. > > Fine, but you were the one who gave the example of "vim running a process > and capturing its output". That is most definitely a child process. Agree. Sorry for the "bad" parallel. > If you have written a C++ program, and have embedded the Ruby interpreter in > it, then by default they will share the same stdin/stdout/stderr. The Ruby > code can also write to stdout and stderr. Why should it not? I have a *ncurses* frontend for my editor. If ruby outputs data to stdout/stderr then the console gets messed up. > If you want to intercept it, so that when Ruby does "puts" it goes into a > string, then you can redirect Ruby's output stream as explained before: > > $defout = StringIO.new(...) > puts "Hello" yes exactly. > If the Ruby process spawns a child, using backtick or Kernel#system, THEN IT > IS A CHILD of your C++ program (the parent process is one and the same). If > you don't use popen then it will share the same Unix file descriptors for > stdout and stderr. This is how Unix works. YES - now i understand. You have teached me well :-) This is actually where the problem lies.. how can I be that silly. I think I can handle it from here (setup some pipes in C++). I will add this to the ruby-embed-into-c++ tutorial http://metaeditor.sf.net/embed/ [snip] > > I'm sorry, frustration is starting to set in for me. For my sanity I think I > will have to ignore this thread now. Thanks for everything... You have provided me with much important knowledge. I am sorry for being mean to you.. but that because I recenly switched to the dark side (soon I'll be in the-matrix mode). -- Simon Strandgaard