Ruby Rye,方法执行ps -aux shell命令时出现错误

时间:2014-12-18 18:36:20

标签: ruby

我安装了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命令正常运行并列出文件的输入 但是,对于execute命令,我收到以下错误:

lib / rye / box.rb:462:在`method_missing'中:ps aux | grep ruby​​> / tmp / ruby​​-process-list(Rye :: CommandNotFound)

我是否需要先添加命令?我假设execute方法将执行任何用户定义的shell命令

1 个答案:

答案 0 :(得分:4)

在使用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,tildas等)运行任何命令(无论白名单中定义的是什么)。

“etc”部分包括管道。