从模块调用代码并自从菜单中的选择选项执行它

从模块调用代码并自从菜单中的选择选项执行它

问题描述:

我不明白为什么当我执行我的代码时,我选择了他没有做任何事情而离开的第一个选项。 你会在下面找到我的水晶脚本的代码。从模块调用代码并自从菜单中的选择选项执行它

require "colorize" 
class Application 

    def initialize 
    mainMenu 
    end 

    def mainMenu 
    puts "you are going to install the software?" 
    puts " 1: To install the soft you have to be root".colorize.fore(:red).bold 
    puts " 2: Modify module" 

    case gets 
    when "1" 
     puts "installation of the software.." 
     install_soft 

    when "2" 
     puts "you chose option2" 
    end 
    end 

    Application.new 
end 

这是我使用方法install_soft进行安装的代码。 他正确打印我的puts " you are .."但它确实没有别的:(

module InstallSoft 
    def install_soft 
    puts "you are in def install_soft " 
    output = IO::Memory.new 
    Process.run("bash", args: {"eole/lib/bash_scripts/installation.sh"}, output: output) 
    output.close 
    output.to_s 
    end 
end 

的输出我发现了一个解决方案,看到现场的堆栈输出:真

Process.run("lib/bash_scripts/installation.sh", shell: true, output: true, error: true) 

那么,应该怎么做呢?你收集过程的标准输出在存储IO并将其转换为字符串。

如果您要打印过程中您的应用程序的标准输出的标准输出,你要么必须转发(使用STDOUT而不是存储IO)或打印存储的IO到标准输出(puts install_soft)的内容。

我找到我要使用的解决方案

Process.run("lib/bash_scripts/installation.sh", shell: true, output: output) 
      output.close 
      output.to_s 

但目前我不能让我的脚本:(

+0

'把output'应打印输出你的输出。另外,请确保安装脚本产生任何要捕获的输出。 –