From: Brian Candler Date: 2009-06-01T22:09:32+09:00 Subject: Re: How can I get command's result code, which executing via ssh One other point. It's very dangerous to do ch.foo { |ch| ... } because (in ruby 1.8) 'ch' is bound to the same variable in both cases. That is, the value assigned to the block parameter also changes the outer 'ch'. So you should call them something different. The finished program becomes: require 'rubygems' require 'net/ssh' Net::SSH.start('localhost', 'yourname') { |ssh| ssh.open_channel { |chan| chan.on_request('exit-status') { |ch, data| puts "process terminated with exit status: #{data.read_long}" } chan.exec('false') { |ch, success| puts success } } } -- Posted via http://www.ruby-forum.com/.