From: Michael Guterl Date: 2008-10-20T02:31:38+09:00 Subject: Re: Error Exception if script doesn't run On Sun, Oct 19, 2008 at 1:19 PM, jackster the jackle wrote: > Brian Candler wrote: >> jackster the jackle wrote: >>> $? equals 0, however if I change the path to js.txt to something that >>> doesn't exist in order to make it fail, $? has a value of 256. >> >> That's because the low-order 8 bits of $? encode something different; >> the next 7 bits are the exit code (0 to 127). Use $?.exitstatus to get >> that. >> >> http://www.ruby-doc.org/core/classes/Process/Status.html >> >>> I thought $? should always have a value of 1 when it fails? Why is it >>> 256? >> >> The exit status in this case is 256 >> 8, which is 1. > > this code seems to work well for what I need: > > `cp /xhome/jsmith/js.txt /home/jsmith/js2.txt` > unless $?.success?; raise "error with: #{$0}" ; end > > I would like to be able to add the line number of the file into the > error message with the file name ($0) but when I try other global > variables such as $@ or $. I don't get the line number of the script > that failed? > Look into __LINE__ HTH, Michael Guterl