I am trying to execute the "top -n 1" command in ruby using the Open3 module in ruby.
This is my code
command = "top -n 1"
Open3.popen3 (command) do |i,o,e,t|
        i.close
        exit_status = t.value
        unless exit_status.success?
                puts "NOPE"
        end
        t.value
end
All I get is NOPE. Even if I try to print o.read or o.gets all I get is a blank line.
Is there anyway I can use open3 to execute that command? Are there any other ways of executing it ? Am I doing something wrong?
I see that I can use the backticks(`) to execute system command. Is that a good practice? I saw several articles and blogs saying it isn't.
Thanks in advance.
 
    