这个输出结果是一个包含两个字符串的列表,每个字符串代表了一个要执行的命令。

如果想要逐行执行这些命令并获取输出结果,可以使用以下代码:

import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('hostname', username='username', password='password')

commands = ['display memory', 'display cpu']
for command in commands:
    stdin, stdout, stderr = ssh.exec_command(command)
    output = stdout.readlines()
    # 处理output,例如打印每行内容
    for line in output:
        print(line.strip())

ssh.close()

在循环中,每次执行一个命令并获取输出结果。使用readlines()方法获取输出结果的每一行,并进行相应的处理。由于readlines()方法返回的是一个包含每行内容的列表,因此需要使用循环逐行处理输出结果。

需要注意的是,输出结果可能包含特殊字符,例如换行符、制表符等。可以使用strip()方法去除每行开头和结尾的空白字符

readlines方法逐行读取输出结果。需要注意输出结果可能会包含特殊字符需要根据具体情况进行处理。display memoryn display cpun

原文地址: https://www.cveoy.top/t/topic/hcIV 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录