【问题标题】:How to display the output of a script launched from another Ruby script in real time?如何实时显示从另一个 Ruby 脚本启动的脚本的输出?
【发布时间】:2014-10-03 15:17:03
【问题描述】:

我编写了一个 Ruby 脚本,在其执行的某个时刻,它将运行 bundle install 以从 Gemfile 安装 gem。这是相关部分:

puts "installing gems ..."
puts `bundle install --without production`
puts "gems installed."

这里发生的情况是,虽然bundle install 命令已正确执行,但我只有在安装了所有 gem 后才能在 CLI 中看到输出。这意味着我首先得到installing gems ...,然后它等待,我得到bundle install 的所有输出行加上gems installed 消息。

有没有办法在 bundle install 执行时实时逐行显示输出?

【问题讨论】:

    标签: ruby output command-line-interface


    【解决方案1】:

    一种选择是使用Kernel#system 而不是反引号:

    system "bundle install --without production"
    

    【讨论】:

    • 太棒了!它正是我需要的。我确信反引号和system 是别名,但显然,我完全错了。谢谢。
    猜你喜欢
    • 2015-09-26
    • 2022-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多