From: Roger Pack Date: 2009-12-10T23:48:45+09:00 Subject: Re: Redirecting standard output Omar Campos wrote: > Hi all, > > Is there a way to redirect the standard output, so that command like > puts write to a file instead of the console? Using this as a way to shamelessly promote my 'desc_method' gem... :) >> $stdout.methods => [:reopen, :print, ...] >> require 'desc_method' => true >> $stdout.desc_method :reopen sig: # arity: -1 appears to be a c method searching ri for IO#reopen... -------------------------------------------------------------- IO#reopen ios.reopen(other_IO) => ios ios.reopen(path, mode_str) => ios From Ruby 1.9.1 ------------------------------------------------------------------------ Reassociates _ios_ with the I/O stream given in _other_IO_ or to a new stream opened on _path_. This may dynamically change the actual class of this stream. f1 = File.new("testfile") f2 = File.new("testfile") f2.readlines[0] #=> "This is line one\n" f2.reopen(f1) #=> # f2.readlines[0] #=> "This is line one\n" (end ri) => "#" >> $stdout.reopen("abc", "w") Enjoy -r -- Posted via http://www.ruby-forum.com/.