paramiko-python exec_command()无法在通道类型元组上工作:(

时间:2011-07-19 22:22:38

标签: python paramiko

测试功能

def GetTestFile():
    sshConn = paramiko.SSHClient()
    sshConn.load_system_host_keys()
    sshConn.connect(host, port, usrnm, pwrd)
    (connin, out, err) = sshObj.exec_command("cat test.txt")
    print out.readlines()
    lines = []
    for i in out.readlines():
        lines = lines.append(i)
        print lines
    print "Lines: ", lines
    sshConn.close()

如您所知,这会在远程服务器上执行简单的cat。我想将输出的内容传输到行,但是当它输出为[]时(我检查了for循环似乎没有因某些奇怪的原因被执行)

1 个答案:

答案 0 :(得分:1)

list.append方法不返回列表,它是就地附加。你想要

for i in out.readlines():
    lines.append(i)
    print lines