On Sun, Jul 06, 2003 at 04:59:16PM +0900, Mark Wilson wrote:
> >How do I get access to what's in $stderr in the form of a string?
> >
> >[snip]
> 
> >I'm aware of a way to do something similar provided by Brain Candler 
> >in an earlier message:
> >
> >http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/71151
> >
> >I am having trouble following how I might implement the above, and I 
> >don't know if it is the answer to the difficulty I am having.
> >
> >[snip]
> 
> I tried Brian's solution and it worked perfectly. I should have tried 
> it before asking. I still don't really follow how it works (it's a 
> little like magic to me), so any education on that would be good.

It forks off a subprocess, passes a pipe to the child's stdout and stderr,
and reads from the other end of the pipe into a string.

It was an attempt to solve a different problem: how to capture stdout/stderr
of *any* arbitary Ruby command, including one which calls C. It's inefficent
because of the extra fork (since Kernel#system itself does a fork)

> I think that a declarative way of accessing the contents of what a 
> method writes to stderr would be a good addition to Ruby.

It has been suggested that an alternative version of Kernel#system which
captures stdout and stderr to separate variables would be good to have. You
can currently capture stdout using backtick or %x{}, but not stderr.

There is a straightforward version here:
http://ruby-talk/72502

However this is an implementation of regular 'system', not the
Shell.def_system_command / #transact / #dialog you are using (which I had
never come across before)

Regards,

Brian.