From: Jim Freeze Date: 2005-02-25T14:24:48+09:00 Subject: Re: How to extend $stdout#write for system calls? * Joel VanderWerf [2005-02-25 08:27:04 +0900]: > Joel VanderWerf wrote: > >class IO > > def tee > > IO.popen("-") do |pipe| # Won't work on mswin. Windows shmwindows. So what? ;) > > if pipe # parent > > while (str = pipe.gets) > > puts str > > $stdout.puts str > > end > > else # child > > yield > > end > > end > > end > >end > > > >f=File.open("/tmp/tee-example-output", "w+") > > f.tee do > puts "something" > puts "something else" > system("echo", "from system") > end Nice twist on this. I like it, but maybe I'm too tired. How would I integrate capturing stderr also? I tried popen3, but couldn't get that to work either. -- Jim Freeze Code Red. Code Ruby