Hi all, 

I've read a few posts that talk about redirecting
stdout etc, but I haven't been able to make things
work.  My current best effort is:

module Redirector

  def defRedirector( fileName)

    yield				# Debug

    begin
      save_defout = $defout.clone 	# a dup by any
other name
      $defout.reopen(fileName, 'w')			# dup2,
essentially
      yield                       	# call the block
    ensure
      $defout.reopen(save_defout) 	# restore original
$stdout
      save_defout.close           	# and dispose of
the copy
    end
  end
end

Then I test by executing:
require "Redirector"
include Redirector
defRedirector( 'testFile.txt') { puts "This is a
test"}

I get different results depending on whether I'm in
RubyWin, irb, or executing from a prompt.  In general,
I get an empty file with output going to the screen.  

It seems like this is all rather fiddly.  I've been
programming Ruby for a grand total of a week or so,
but not being able to reliably redirect could put a
real dent in my project.  I'm trying to write a front
end to some analysis tools, and I need to write config
files for the tools to munch on.

Thanks,

Brian



__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/