【发布时间】:2013-10-26 04:18:45
【问题描述】:
我截断了以下代码,以允许在两台 Windows 机器上执行。我安装了copssh 以在 Windows 机器中作为 ssh 服务器工作,我正试图让它工作......
cmd = "python --version"
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
client.connect("myhost",username="admin", password="adminpass")
print "restarting machine ... "
stdin, stdout, stderr = client.exec_command(cmd)
print stdout.readlines()
当执行以下代码时,我得到:
C:\wcat>python main.py
C:\Python27\lib\site-packages\paramiko-1.11.0-py2.7.egg\paramiko\client.py:95: U
serWarning: Unknown ssh-rsa host key for 192.168.2.4: 7bf6ba243a3daaa994e0b42067
9cfb30
(key.get_name(), hostname, hexlify(key.get_fingerprint())))
restarting machine ...
[]
什么都不返回...即使是像cd C:\ && dir 这样的简单Windows 命令也会返回[]。我也在从我正在 ssh-ing 到另一台机器的机器上做同样的事情,它可以工作,但解决方法不是......可能的原因是什么?
【问题讨论】:
-
@Kyle
Stderr <paramiko.ChannelFile from <paramiko.Channel 1 (open) window=2097152 -> < paramiko.Transport at 0x2a03bd0L (cipher aes128-ctr, 128 bits) (active; 1 open c hannel(s))>>> -
@philippe:看起来它只是标准错误的
repr:如果你从文件中读取(例如,print stderr.read()),你会得到什么吗? -
@Thanatos ...当我打印 stderr.read() 我什么也没得到...
print stdout.channel.recv_exit_status()返回 127 ...这是什么意思?