On a bash console, if I do this:
cd mydir
ls -l > mydir.txt
mydir.txt
You can use override $stdout
to redirect the console output:
$stdout = File.new('console.out', 'w')
You may also need to call this once:
$stdout.sync = true
This will redirect all output to the file. If you want to temporarily redirect the output make sure that you store the original value of $stdout
so you can change it back.