AutoTestProject
2022-06-24 10:53
采纳率: 0%
浏览 20

python ssh执行刷机回显

需要做一个ssh刷写命令
class Mcu:
def init(self):
self.ssh_client = paramiko.SSHClient()
self.ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy)
self.ssh_client.connect(hostname='', port=22, username='t', password='2')
print('连接成功')

def WriteMcu_A(self):
    # stdin为输入的命令
    # stdout为命令返回的结果
    # stderr为命令错误时返回的结果
    stdin, stdout, stderr = self.ssh_client.exec_command('查看版本')  # cmd执行命令
    result = stdout.read().decode('utf-8')  # 读取执行结果
    print(result)
    self.version = re.findall("version::.+", result)
    print(self.version)
    print("第一步")

    stdin, stdout, stderr = self.ssh_client.exec_command(指定文件)
    result = stdout.read().decode('utf-8')  # 读取执行结果
    print(result)
    print("第二步")
    stdin, stdout, stderr = self.ssh_client.exec_command('执行开始刷写的命令')
    print("第三步")
    ##  这里需要显示刷写的进度,percent == [100.00] and result == [0] 时刷写完成
    #time.sleep(3000)

    results = stdout.read().decode('utf-8')
    print(results)
    # percent = re.findall("percent:n:.+", results)
    # result = re.findall(" result:n:.+", results)
    # print(percent,result)
    # if percent == [100.00]:
    #     if result == [0]:
    stdin, stdout, stderr = self.ssh_client.exec_command('刷写完成')
    result = stdout.read().decode('utf-8')  # 读取执行结果
    print(result)
    print("第四步")
    self.ssh_client.close()

1条回答 默认 最新

相关推荐 更多相似问题