以下是我正在使用的代码:
require 'rye'
r = Rye::Box.new("ip_of_server", :user => "username_of_server", :password => "password_of_server", :safe => false)
r.execute("which testing")
我得到以下内容:
(cmd: which testing; status: 1)
from /var/lib/gems/2.3.0/gems/rye-0.9.13/lib/rye/box.rb:855:in `rescue in run_command'
from /var/lib/gems/2.3.0/gems/rye-0.9.13/lib/rye/box.rb:804:in `run_command'
from /var/lib/gems/2.3.0/gems/rye-0.9.13/lib/rye/box.rb:473:in `method_missing'
from (irb):64
from /usr/bin/irb:11:in `<main>'
我知道它不存在但是想接受1的错误状态并获取&#34的数据;其中:没有测试(/usr/local/rvm/gems/ruby-1.9.3-p551 /bin:/usr/local/rvm/gems/ruby-1.9.3-p551@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p551/bin:/usr/local/bin: / usr / bin:/ usr / local / rvm / bin:/ usr / local / bin)(cmd:which testing; status:1)&#34;
我试图修改Rye :: Rap,但似乎我所做的一切并没有改变结果。
我知道当我运行r.execute并将值返回给变量时我可以进行救援,但是如果我能接受失败,我想知道是否有使用Rye的话。
irb(main):012:0* begin
irb(main):013:1* r.execute("which testing")
irb(main):014:1> rescue => e
irb(main):015:1> merp = e.message
irb(main):016:1> end