I am trying to show in Chrome using Sinatra, the result of ls. But the explorer gets in an "Connecting..." loop.
My code is:
require 'rubygems' if RUBY_VERSION < "1.9"
require 'sinatra/base'
#This is the webservice to launch the gamma project
#Using Request at the principal webpage
class MyApp < Sinatra::Base
get '/' do
result = exec "ls"
puts result
end
end
I am not sure of that puts, I think that maybe is not the apropiate method. What could be happening and how can I solve it?
PS: In the explorer I used localhost.com:4567/
Use the backticks ( ` ) instead of the Kernel#exec command. The former returns a string that you can then use in your ruby process. The latter throws your execution context into a new process and has no return value.
Note that the call to
putswill not look very nice and that you'll probably want to format it or parse/manipulate it further. But at least you'll get something you can use.