我如何从.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