Sulo Wijetunga Sulo Wijetunga - 2 days ago 5
Ruby Question

How to read STDERR status using Ruby?

This code is not working properly:

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


How do I see what the STDERR/STDOUT status code is?
I tried using
puts
:

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


but it doesn't work.

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
Comments