我如何從.execute
方法的Net-SSH-殼牌Ruby Net-SSH-Shell從執行中獲得標準!方法
具有良好的「醇淨-SSH標準輸出,這很容易
Net::SSH.start('host','user') do |ssh|
puts ssh.exec! 'date'
end
給我Tue Jun 19 23:43:53 EDT 2012
但如果我嘗試使用外殼,我得到一個過程對象
Net::SSH.start('host','user') do |ssh|
ssh.shell do |bash|
output = bash.execute! 'ls'
puts output
end
end
給我#<Net::SSH::Shell::Process:0x007fc809b541d0>
我無法在稀疏文檔中找到關於如何輕鬆獲得標準的任何內容。還有就是on_output
方法,但似乎並沒有爲我做任何事情,如果我用execute!
方法
我也試過路過一個塊.execute!
像
bash.execute! 'ls' do |output|
puts output
end
,但我仍然得到過程#<Net::SSH::Shell::Process:0x007fc809b541d0>
我需要標準輸出的變量,我可以使用,我需要一個實際的有狀態的登錄shell,其準系統Net-SSH不會做我的知識。
任何想法?
編輯
沿@vikhyat的建議同樣的想法,我想
ssh.shell do |bash|
process = bash.execute! 'ls' do |a,b|
# a is the process itself, b is the output
puts [a,b]
output = b
end
end
但b
總是空的,甚至當我知道這個命令返回結果。
不幸的是,我有。傳遞給'.on_output'的塊永遠不會被調用。雖然 – wmarbut
hidden_premise:請查看我的編輯答案。 – vikhyat
我對你的修改後的答案做了一個小修改,包括'bash.wait!'和'bash.execute! '出口',但這是票。謝謝! – wmarbut