def ssh_command(command, subsession=nil)
exit_status = 0
subsession ||= session
command = fixup_sudo(command)
command.force_encoding('binary') if command.respond_to?(:force_encoding)
subsession.open_channel do |ch|
ch.request_pty
ch.exec command do |ch, success|
raise ArgumentError, "Cannot execute #{command}" unless success
ch.on_data do |ichannel, data|
print_data(ichannel[:host], data)
if data =~ /^knife sudo password: /
ichannel.send_data("#{get_password}\n")
end
end
ch.on_request "exit-status" do |ichannel, data|
exit_status = [exit_status, data.read_long].max
end
end
end
session.loop
exit_status
end