需要做一個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()