我安装了 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)
我需要先添加命令吗?我假设 execute 方法将执行任何用户定义的 shell 命令
最佳答案
在使用 execute 方法之前,您必须禁用安全模式:
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')
如文档中所述:
When safe-mode is disabled, you can run any command (regardless of what is defined in the whitelist) with any valid arguments (fileglobs, tildas, etc...).
“etc”部分包括管道。
关于Ruby Rye,执行 ps -aux shell 命令时出现 Method Missing 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27553415/