车载testing 2022-06-24 10:53 采纳率: 0%
浏览 45

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条回答 默认 最新

  • aabbabababaa 2022-06-24 11:04
    关注

    运行有报错?

    评论

报告相同问题?

问题事件

  • 创建了问题 6月24日

悬赏问题

  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services