From: Andrew Walrond Date: 2003-05-03T00:01:20+09:00 Subject: Re: temporary redirection of stdout Hi Brett > > I don't see the same behavior: > > vor-lord:/tmp> ruby -e 'File.open("output","w") { |f| > puts("To the screen") > sso = $stdout > $stdout=f > puts("To the file") > $stdout = sso > puts("To the screen again") > } > ' > To the screen > To the screen again > vor-lord:/tmp> cat output > To the file > vor-lord:/tmp> ruby -v > ruby 1.7.2 (2002-02-21) [i386-linux] > > > This appears to be version specific: > > vor-lord:/tmp> /usr/bin/ruby -e 'File.open("output","w") { |f| > puts("To the screen") > sso = $stdout > $stdout=f > puts("To the file") > $stdout = sso > puts("To the screen again") > } > ' > To the screen > vor-lord:/tmp> cat output > To the file > To the screen again > vor-lord:/tmp> /usr/bin/ruby -v > ruby 1.6.7 (2002-03-19) [i386-linux] > > This is interesting. Perhaps $stdout has been fixed to be a proper reference in newer versions? Whatever, the .dup solution should be fine for both versions, right? Andrew