"Brian Candler" <B.Candler / pobox.com> schrieb im Newsbeitrag news:20030509224516.GA53292 / uk.tiscali.com... > On Fri, May 09, 2003 at 09:55:32AM +0900, Simon Strandgaard wrote: > > Problem is almost solved, thanks for pointing me in the right direction. > > > > I have been experimenting a little with a pipe between 2 threads :-) > > TODO: this has to be integrated into my embedding code. > > This might have others interest. > > Is this planned as part of "Embedding Ruby in C++ tutorial"? If so, I hope > you don't mind if I argue that it doesn't belong there. > > I had a bit of a think about this, and setting Ruby aside for the moment, > why not consider the following question similar to your original one: > > If I write a subroutine (function) in C++, how can I wrap it so that > any output it generates does not go to stdout, but is discarded or > captured in a string? > > Now, I'm not a C++ programmer, but I imagine the answer goes something along > the lines of: "change cout to point to a new object, so that cout << "foo" > writes to this object rather than what cout normally points to". Or you > could close fd 1 and fd 2 and reopen them pointing to /tmp/result or > /dev/null. You better not change cout or cerr itself but the streambuf it points to. In C++ cout and others are for formatting while streambuf and others do the transport. Regards robert