From: Greg Willits Date: 2009-12-21T05:42:11+09:00 Subject: Re: How capture console error messge for logging? Greg Willits wrote: > I've been searching & reading, but not finding (or perhaps just not > understanding) how I can capture as a string the exact same error > message text that would normally get dumped to Terminal. > > begin > puts "hello" > bogus_command > rescue > # now what? > # I was hoping this would work > # x = $stderr.print > # but it doesn't > end DOH!! As soon as I hit send, I realized I could try one more thing: x = $! That gave me the error message. And then a key word popped into my head. I wanted the "stack trace." More googling gave me the .backtrace method. So now I have: begin puts "hello" bogus_command rescue=> err x = "#{err.backtrace[0] #{err}}" end This works perfectly. So, unless there's A Better Way someone wants to suggest, I think I am good. thanks for listening :-) -- greg -- Posted via http://www.ruby-forum.com/.