Sulo Wijetunga Sulo Wijetunga - 8 days ago 6
Ruby Question

How to read sterr status from Ruby?

I have following ruby and not working properly

my_command = %x{java -version &>/dev/null}
if $? != 0


In this how do I see what the stderr/stdout status code?
I tried put below, nothing works..

puts "values ===> $? or or '$?' my_command or #{my_command} %x{echo $?}"

Answer

To get the status code :

stdout    = %x(ls -l)
exit_code = $?.exitstatus

and then

if exit_code == 0 then
  puts "Success"
else
  puts "Problem"
end