From: David Alan Black Date: 2001-08-08T08:22:19+09:00 Subject: [ruby-talk:19318] Re: how to redirect $sdtout Hello -- On Wed, 8 Aug 2001, markus jais wrote: > $old_fh = select(LOGFILE); # switch to LOGFILE for output > print "Countdown initiated ...\n"; > select($old_fh); # return to original output > print "You have 30 seconds to reach minimum safety distance.\n"; > > my ruby solution does not work! > > logfile = File.new("log.txt", "w+") > old = $stdout.clone > $stdout.reopen(logfile) > print "Countdown initiated ...\n"; > $stdout.reopen(old) > old.close > print "You have 30 seconds to reach minimum safety distance.\n"; You don't like #puts? :-) > both strings are written to stdout and the file log.txt is empty. > can anybody tell me why?? I found something similar > in the mailing list archive, but it just doesn't work Could you/should you do this with $defout rather than $stdout? logfile = File.new("log.txt", "w+") old = $defout $defout = logfile print "Countdown initiated ...\n"; $defout = old print "You have 30 seconds to reach minimum safety distance.\n"; or something like that. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav