私には機能があります
def run_through_ssh(command)
host = $edumate_server
user = 'user'
pass = '******'
output = Array.new
Net::SSH.start( host, user, :password => pass ) do|ssh|
output = ssh.exec(command)
#output = ssh.exec(command+" 2>&1")
end
return output
end
リモートサーバーで必要なコマンドを正しく実行しますがoutput
、リモートで実行されたコマンドが画面に出力するものが変数に含まれていません。私はこの関数をsinatra内で使用していますが、不思議なことに、sinatraを実行している画面に出力が表示されます。
リモートで実行されたコマンドの出力をキャプチャするにはどうすればよいですか?
出力変数には次のようなものが含まれます
#<Net::SSH::Connection::Channel:0x3fe40c0 @remote_maximum_window_size=2097152, @
eof=false, @on_open_failed=nil, @remote_window_size=2097152, @closing=true, @pro
perties={}, @local_maximum_packet_size=65536, @on_process=nil, @type="session",
@remote_id=0, @on_confirm_open=#<Proc:0x031f64a0@C:/Ruby187/lib/ruby/gems/1.8/ge
ms/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:320>, @on_request={}, @local_
id=0, @on_extended_data=#<Proc:0x031f6560@C:/Ruby187/lib/ruby/gems/1.8/gems/net-
ssh-2.2.1/lib/net/ssh/connection/session.rb:332>, @local_maximum_window_size=131
072, @on_eof=nil, @connection=#<Net::SSH::Connection::Session:0x3fe42a0 @options
={:logger=>#<Logger:0x400cb90 @level=4, @progname=nil, @logdev=#<Logger::LogDevi
使用して
- ruby 1.8.7 (2010-08-16 パッチレベル 302) [i386-mingw32]
- ネット-ssh (2.2.1)