From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-05-07T17:35:14+09:00 Subject: Re: capture output On Wed, 07 May 2003 17:44:22 +0900, Brian Candler wrote: > On Wed, May 07, 2003 at 09:33:50AM +0900, Simon Strandgaard wrote: >> The remaining question: Why does the output differs when >> I run the program several times ??? > > Because you are killing threads before they have finished doing their useful > work? The threads should exit themselves on seeing an EOF condition on the > read stream, then you can use t.join to wait for them. How do I detect EOF ? > But I wonder if you are over-complicating things, if you just want to > capture output into a string. How about: > > mystring = `command 2>&1` Not doable.. The full story why I need to make ruby silent: I am writing a tutorial on how to embed ruby into c++. http://metaeditor.sf.net/embed/ I want the tutorial-readers to know that they don't have to worry about such "piping" issues and that ruby is behaving like an c++ iostream, though which ALL output is delivered. I assume that this "piping" stuff will scare most people from attempting to embed ruby. Therefore this is not doable! > Otherwise, the standard way of doing this is with IO.popen: see > http://ruby-talk.org/68660 > See the follow-ups for info on actually redirecting your stdout into a file. As I said before the standard way is not doable! I re-read the thread and found some good ideas :-) > cat test.rb $stdout = File.open("log.txt","w") $stdout.sync = true # what is sync ??? $defout = $stderr = $stdout puts "1" system("ls") puts "2" > This can capture everything, just what I need! Now I just have to fit it into the earlier mentioned code. Could "sync" be the solution to the glitch problem ??? -- Simon Strandgaard