我在下面的返回代码中发现了一些差异。可能是我没有以正确的方式使用。每次我打印返回码时,它都会打印出与第一个返回码相同的内容。我需要重置返回码吗?我的意思是在下面的示例中,我将两个命令的返回码都设为 2。现在,当我交换两个命令时,我的意思是替换ls -al;exit\n
为ls -al file_not_exist;exit\n
,反之亦然,它会打印返回代码 0。每次它打印与第一个返回的返回代码相同的返回代码。
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('localhost', username='sam', password='mypassword')
channel = ssh.invoke_shell()
channel.send('ls -al file_not_exist;exit\n') #Sending to list a file which doesn't exist
time.sleep(3)
print "My 1st command exit status is: ",channel.exit_status_ready()
print "My 1st command return code is: ", channel.recv_exit_status()
channel.send('ls -al;exit\n')
time.sleep(3)
print "My 2nd command exit status is: ",channel.exit_status_ready()
print "My 2nd command return code is: ",channel.recv_exit_status()
我需要打印每个命令的返回码。你能帮我解决这个问题吗?