I notice that any shell commands that I have in the script that fail do not trigger a Ruby exception, how do I get my Ruby script to send these? thanks jack Brian Candler wrote: > jackster the jackle wrote: >> I need to know if my script fails to run for any reason and capture the >> exception. I know how to use "rescue" for small pieces of code but how >> can I capture the stderr for anything in the script? > > If you want to capture only an *exception* then wrap it like this: > > begin > > .. rest of script > > rescue Exception => e > .. do something with e, e.g. write it to a log file > end > > However if you want to capture everything written to stderr then that's > a different problem. That's the responsibility of whoever started the > Ruby process, since it would have passed it an open file descriptor for > stderr (fd 2). For example, if you are starting ruby from a shell, then > > $ ruby foo.rb 2>errors.log > > But if you were launching it from another Ruby process, then look at > open3.rb in the standard library. -- Posted via http://www.ruby-forum.com/.