我正在Ubuntu上用Python编写一个程序。在该程序中,我试图在完成远程机器(RaspberryPi)上的任务“删除文件”后打印一条消息,该机器已连接到网络。
但是,在实际操作中,打印命令并没有等待远程机器上的任务完成。
有人可以指导我如何做吗? 我的代码如下:
import paramiko
# Connection with remote machine
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('192.168.2.34', username='pi', password='raspberry')
filename = 'fahad.txt'
filedelete ='rm ' + filename
stdin, stdout, stderr = client.exec_command(filedelete)
print ("File Deleted")
client.close()