I am getting some discrepancy in the return code below. May be I am not using in the proper way. Every-time I print the return code, it prints the same as the first one has returned. Do I need to reset the return code. I mean in the following example, I am getting the return code as 2 for both the commands. Now when I interchange both the commands, I mean replace ls -al;exit
with ls -al file_not_exist;exit
and vice versa, it prints return code 0. Each time it prints the same return code as the first one has returned.
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
) #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
)
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())
我需要印刷每个指挥部的返回代码。 请帮助我如何解决这一问题?