From: jackster the jackle Date: 2008-10-21T03:30:44+09:00 Subject: Re: Error Exception if script doesn't run I finally figured out the last problem which was why some of my Ruby generated errors that were were not able to be included in my sendmail command. The problem was the error that was contained in my "e" value had some text with ` and ' characters in them as follows: undefined local variable or method `bad_code_here' for main:Object Once I added some gsub code to remove those characters, all is working well and I get an email with the error regardless of whether a shell command or ruby code were the cause of the error. Here is my final code which I will now implement in all my scripts (unless someone sees another problem) so I'm no longer blind sided by know-it-alls here at work that come to me with "you know your scripts have failed, don't you?" :-) [code] begin z = `cp /home/jsmith/js.txt /home/jsmith/js2.txt` unless $?.success?; raise "Shell Command Failure for line #{__LINE__} in #{__FILE__}" ; end # The following line of code will cause Ruby to generate an error bad_code_here rescue Exception => e if e puts e e.to_s.gsub!("'","-") e.to_s.gsub!("`","-") %x{echo "Subject: Script Error: #{__FILE__}:#{__LINE__}\n\n#{e}" | /usr/sbin/sendmail -f my_server\@gmail.com john.smith\@email.com} end end [/code] Thanks to everyone for all the help, I learned alot. jack -- Posted via http://www.ruby-forum.com/.