Sulo Wijetunga Sulo Wijetunga - 1 year ago 93
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 "values ===> $? or or '$?' my_command or #{my_command} %x{echo $?}"

but it doesn't work.

Answer Source

To get the status code :

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

and then

if exit_code == 0 then
  puts "Success"
  puts "Problem"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download