开发者

Execute script and show output/progress in view [Ruby/Sinatra(Rails)]

开发者 https://www.devze.com 2023-03-30 21:16 出处:网络
I have a deploy script that is called from a helper in my Sinatra app. I want show a \"deploying\" view/page, then exec the script.

I have a deploy script that is called from a helper in my Sinatra app.

I want show a "deploying" view/page, then exec the script.

Then when the script is finished, show a new page with text box with the script output in.

How can this be done?

# update.rb - the main app
helpers do
  def run_update
    command = "./sc开发者_运维问答ript.sh"
    @ok = system( command )
  end
end

post '/version' do
  run_update     # putting this after the erb call doesnt fix it!?
  erb :version
end

Currently it hangs after the post is made from the main page. Then when the script is finished it displays the version.erb file.


I think what I was looking for was IO#popen

Runs the specified command as a subprocess; the subprocess’s standard input and output will be connected to the returned IO object.


You can redirect the output to a file and display the file over HTTP and keep refreshing the page every x seconds

get '/progress' do # This page should be refreshed every x seconds

  # render the file here

end
0

精彩评论

暂无评论...
验证码 换一张
取 消