"Ruby run (execute) command line"

Also a gist on github. This code snippet is an example of how to execute a command line argument in ruby and display the output

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#!/usr/bin/env ruby
do_and_report("ls")

#Small function to run a command and output return values
def do_and_report(command)
   f = open("| #{command}")
   g = Array.new
   while (foo = f.gets)
      g << foo
   end
   g.each do |element|
      puts element
   end
end

social