ruby-on-rails - 执行脚本并在 View 中显示输出/进度 [Ruby/Sinatra(Rails)]

标签 ruby-on-rails ruby bash sinatra

我有一个从我的 Sinatra 应用程序中的助手调用的部署脚本。

我想显示一个“正在部署”的 View /页面,然后执行脚本。

然后当脚本完成时,显示一个带有文本框的新页面,其中包含脚本输出。

如何做到这一点?

# 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 文件。

最佳答案

我想我要找的是 IO#popen

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

关于ruby-on-rails - 执行脚本并在 View 中显示输出/进度 [Ruby/Sinatra(Rails)],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7187988/

相关文章:

linux - 重定向(>) h5dump 输出到文本文件导致数据丢失

mysql - 为什么我的 Rails 函数在 SQLite 中有效,但在 MySQL 中无效?

ruby-on-rails - 尝试更改密码时设计警告: Can't mass-assign protected attributes: current_password

mysql - 查询记录的最佳方式

ruby-on-rails - ActiveRecord::JDBCError: 错误:无法打开扩展控制文件

ruby-on-rails - 如何调试随机 Timeout::Error: execution expired

linux - 在 bash linux 中为 linux 中的多媒体文件(不是图像)编辑元数据

ruby - 为什么 Ruby 的默认参数值没有分配给 nil 参数?

ruby-on-rails - 如何在 Rails 3.2 中找到 "SystemStackError (stack level too deep)"的来源

bash - 如何从 bash 中的文件中读取文件名列表?