从模块调用代码并在菜单中选择选项后执行它
Call code from module and execute it since a chosing option in menu
我不明白为什么当我执行我的代码时,我选择了他离开的第一个选项而没有做任何事情。
您会在下面找到我的 crystal 脚本的代码。
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
嗯,它应该做什么?您在内存 IO 中收集进程的标准输出并将其转换为字符串。
如果您想将进程的标准输出打印到应用程序的标准输出,您要么必须转发它(使用 STDOUT
而不是内存 IO),要么打印内存 IO 的内容到标准输出 (puts install_soft
).
我找到了我必须使用的解决方案
Process.run("lib/bash_scripts/installation.sh", shell: true, output: output)
output.close
output.to_s
但目前我无法获得脚本的输出:(
我找到了一个解决方案,可以通过 output:true
实时查看堆栈
Process.run("lib/bash_scripts/installation.sh", shell: true, output: true, error: true)
我不明白为什么当我执行我的代码时,我选择了他离开的第一个选项而没有做任何事情。 您会在下面找到我的 crystal 脚本的代码。
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
嗯,它应该做什么?您在内存 IO 中收集进程的标准输出并将其转换为字符串。
如果您想将进程的标准输出打印到应用程序的标准输出,您要么必须转发它(使用 STDOUT
而不是内存 IO),要么打印内存 IO 的内容到标准输出 (puts install_soft
).
我找到了我必须使用的解决方案
Process.run("lib/bash_scripts/installation.sh", shell: true, output: output)
output.close
output.to_s
但目前我无法获得脚本的输出:(
我找到了一个解决方案,可以通过 output:true
实时查看堆栈 Process.run("lib/bash_scripts/installation.sh", shell: true, output: true, error: true)