From: "W. James" Date: 2009-12-21T05:50:08+09:00 Subject: Re: How capture console error messge for logging? Greg Willits wrote: > OS X, Ruby 1.8 > > 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. > > So, if I write this to generate an error: > > puts "hello" > bogus_command > > I'll get a file name, line number, and description of an error dumped > to the Terminal. > > How do I snag all that text so I can add it to a log file? > > Obviously, I'd start with a begin/rescue and inside rescue I'd do > something. I've fiddled with some examples I've seen but nothing is > doing what I want. I just want that same text captured as a string > into a variable I can then use however I want. > > begin > puts "hello" > bogus_command > rescue > # now what? > # I was hoping this would work > # x = $stderr.print > # but it doesn'truby -e"puts X" 2>data > end > > I'm sure it's some standard *nix thing, but I'm not getting it. > > Thanks. > > -- greg willits ruby -e"puts X" 2>errors.log --