Sulo Wijetunga Sulo Wijetunga - 1 year ago 100
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 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