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/
As @pgblu pointed out you should use backticks. https://stackoverflow.com/a/18623297/1279355
And the second thing,
puts
print the result only to your shell/log, but to see the result in your chrome you need either:or
As you can see the return is optional, if there is no return Sinatra just displays the last variable/operation.