# Redirecting TestRunner output from console to file

**URL:** <https://www.ruby-forum.com/t/redirecting-testrunner-output-from-console-to-file/167292>\
**Category:** Ruby\
**Created:** [May 6, 2009, 1:45pm UTC](https://www.ruby-forum.com/t/redirecting-testrunner-output-from-console-to-file/167292 "2009-05-06T13:45:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![the\_zonker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e79b87/32.png) [@the\_zonker](https://www.ruby-forum.com/u/the_zonker)\
**Post date:** [May 6, 2009, 1:45pm UTC](https://www.ruby-forum.com/t/redirecting-testrunner-output-from-console-to-file/167292/1 "2009-05-06T13:45:12Z")

</div>

Hi guys

I’m novice both in Ruby and test/unit, so keep it in mind.

I have the following question:  
How can I redirect the Test Runner output from console to some file or  
string variable?

E.g.  
I run tests with the following arguments

io=File.new(‘results.txt’, ‘w’)  
tr=Test::Unit::UI::Console::TestRunner.new(Testcase,“VERBOSE”,io)

So Test IO should write to io variable but indeed it doesn’t contain any  
test results.  
Ruby global variable $stdout is also empty. So it seems strange for me.

If you know what’s wrong with my code and assumptions or some other way  
how to get test results please answear.

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![the\_zonker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e79b87/32.png) [@the\_zonker](https://www.ruby-forum.com/u/the_zonker)\
**Post date:** [May 6, 2009, 8:03pm UTC](https://www.ruby-forum.com/t/redirecting-testrunner-output-from-console-to-file/167292/2 "2009-05-06T20:03:48Z")

</div>

On May 6, 2009, at 04:45 , Vadim Dobrovolsky wrote:

> io=File.new(‘results.txt’, ‘w’)  
> tr=Test::Unit::UI::Console::TestRunner.new(Testcase,“VERBOSE”,io)

Do the simplest thing that could possibly work:

% ruby -Ilib test/test\_blah.rb \> results.txt
