From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-05-11T01:47:46+09:00 Subject: Re: capture output On Sun, 11 May 2003 02:17:14 +0900, Brian Candler wrote: > On Sat, May 10, 2003 at 06:45:36PM +0900, Simon Strandgaard wrote: >> In rubys source for "io.c" there is a bunch of WIN32 checks > .. >> The first 4 of them seems OK.. the rest of them is where I see >> that windows requirs special attention. Windows is wierd. > > It is, but Ruby has coded around those things, so you don't have to worry > about them. To me that's one of the big advantages of a high-level platform > like Ruby: one person solves the problem once and then your code works the > same. Remember im living in a zone between Ruby and C++.. I am a little worried about supporting windows myself. >> Further more I want to be able to run my favorite ruby-scripts unmodified. >> Example: rubyunit outputs to stdout/stderr. > > Bad example, because they've thought of that already. If you run it from the > command line then yes it outputs to stdout/stderr, because you are invoking > the command-line runner; but it has many different runner interfaces. If you > run it using the GTk interface, then it outputs to GTk windows, and it also > has a FOX interface. Look in I only tried the console frontend.. This sounds nice.. I must try out the GUI. I am sorry that I cannot provide you with any good example. > In general, if I wanted to run some program which interacted over > stdin/stdout, but I wanted that interaction to occur inside a GUI window, I > would create a window, fork and exec a child, and talk to it over pipes, so > that I could capture keystrokes and send them down stdin, and capture stdout > and stick it on the screen as it was generated. Remember that im sharing classes with those programs (c++ <=> ruby), marshalling it over a pipe would be slow (but I have no evidence here). What you talking about is a ruby-jail ;-) >> > A. If you don't mind mixing the child's stdout and stderr, you might just >> > get away with using shell redirection: >> > string = `someprog args 2>&1` >> >> This is the answer I have bumped into most-frequently on google. >> BTW: isn't this kind of redirection shell-specific (tcsh, zsh, ksh). > > Yes. Ruby uses /bin/sh by default, so it's not unreasonable to assume > /bin/sh semantics. You might be able to configure it differently. But I > agree with you, I'd certainly be happier asking Ruby to dup fd1 and fd2 to > the same pipe, than using '2>&1'. rock n roll.. >> Look at the "Exception Handling" section and tell me what you think: >> http://metaeditor.sf.net/embed/ > > Looks pretty good to me, I'm not a C++ programmer though so I can't comment > on the mapping between exceptions. Thanks.. there is still much on the TODO for the tutorial and there is still many things I must try out in practice. Then it hopefully will become a really good tutorial :-) -- Simon Strandgaard