Python paramiko 阻塞等待命令执行完毕并返回结果
sshClient = paramiko.SSHClient() ssh_cli = sshClient ssh_cli.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh_cli.connect(hostname=netone_ip, port=22, username='root', password='XXX') stdin, stdout, stderr = ssh_cli.exec_command(f"poweroff") msg = stderr.read().decode(encoding='UTF-8') # print(msg) # 阻塞等待命令执行完毕 while not stdout.channel.exit_status_ready(): pass print(stdout.read().decode())

浙公网安备 33010602011771号