I expected these values to match. They did not match when the shell script exited due to some error condition (and thus returned a non-zero value). Shell $? returned 1, ruby $? returned 256.
>> %x[ ls kkr]
ls: kkr: No such file or directory
=> ""
>> puts $?
256
=> nil
>> exit
Hadoop:~ Madcap$ ls kkr
ls: kkr: No such file or directory
Hadoop:~ Madcap$ echo $?
1
In Ruby
$?is aProcess::Statusinstance. Printing$?is equivalent to calling$?.to_s, which is equivalent to$?.to_i.to_s(from the documentation).to_iis not the same asexitstatus.From the documentation:
$?.to_iwill display this whole 16-bit integer, but what you want is just the exit code, so for this you need to callexitstatus: