How do I get stdout from the .execute
method in Net-SSH-Shell
With good 'ol Net-SSH, this is easy
Net::SSH.start('host','user') do |ssh|
puts ssh.exec! 'date'
end
Gives me Tue Jun 19 23:43:53 EDT 2012
but if I try to use a shell, I get a process object
Net::SSH.start('host','user') do |ssh|
ssh.shell do |bash|
output = bash.execute! 'ls'
puts output
end
end
Gives me #<Net::SSH::Shell::Process:0x007fc809b541d0>
I can't find anything in the sparse docs about how to get standard out easily. There is the on_output
method, but that doesn't seem to do anything for me if I use the execute!
method
I've also tried passing a block to .execute!
like
bash.execute! 'ls' do |output|
puts output
end
but I still get a process #<Net::SSH::Shell::Process:0x007fc809b541d0>
I need the standard out in a variable that I can use and I need an actual stateful login shell, which barebones Net-SSH doesn't do to my knowledge.
Any ideas?
Edit
Along the same ideas of @vikhyat's suggestion, I tried
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
But b
is always empty, even when I know the command returns results.