我安装了 uby-1.9.3-p551 和 rye-v0.9,12
我做了以下工作:
rbox = Rye::Box.new("#{@host}")
puts rbox.cat('/tmp/restorelog.txt')
rbox.execute('ps aux | grep ruby > /tmp/ruby-process-list')
cat 命令功能正常并列出文件的输入但是,对于执行命令,我收到以下错误:
lib/rye/box.rb:462:in 'method_missing': ps aux | grep ruby>/tmp/ruby-process-list (Rye::CommandNotFound(
我需要先添加命令吗?我假设执行方法将执行任何用户定义的 shell 命令
在使用 execute 方法之前,必须禁用safe_mode:
rbox.disable_safe_mode
然后,您的代码将如下所示:
rbox = Rye::Box.new("#{@host}")
puts rbox.cat('/tmp/restorelog.txt')
rbox.disable_safe_mode
rbox.execute('ps aux | grep ruby > /tmp/ruby-process-list')
如文档中所述:
禁用安全模式后,您可以使用任何有效参数(fileglobs、tilda 等(运行任何命令(无论白名单中定义了什么(。
"等"部分包括管道。