执行脚本并在视图中显示输出/进度 [Ruby/Sinatra(Rails)]
我有一个部署脚本,是从我的 Sinatra 应用程序中的助手调用的。
我想显示一个“部署”视图/页面,然后执行脚本。
然后,当脚本完成时,显示一个带有文本框的新页面,其中包含脚本输出。
这是如何完成的?
# update.rb - the main app
helpers do
def run_update
command = "./script.sh"
@ok = system( command )
end
end
post '/version' do
run_update # putting this after the erb call doesnt fix it!?
erb :version
end
目前,它在主页发布帖子后挂起。然后,当脚本完成时,它会显示 version.erb 文件。
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 = "./script.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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我正在寻找的是 IO#popen
I think what I was looking for was IO#popen
您可以将输出重定向到文件并通过 HTTP 显示该文件并保持每 x 秒刷新页面
You can redirect the output to a file and display the file over HTTP and keep refreshing the page every x seconds