1 回答

TA贡献1836条经验 获得超5个赞
正如@Charles 在评论中提到的,
read() 将内容消耗到 EOF。这里没有 EOF,因为 MySQL 仍然处于打开状态。简单的答案是不仅要刷新标准输入,还要关闭它。
你不能这样做,因为 MySQL 仍然是打开的,你的脚本会挂在那里。因此,如果您只想获取数据库,则将查询传递给 MySQL 连接并且可以正常工作:)。
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy() )
ssh.connect(hostname='172.18.109.244', username='somuser',password='bgf')
print "Logged In to EMS"
cmd = 'mysql -h somehost.example.com -uroot -proot -e \'show databases;\''
stdin, stdout, stderr = ssh.exec_command(cmd)
# stdin.write("show databases;")
stdin.write('\n')
stdin.flush()
print stdout.read()
添加回答
举报