channel.recv_exit_status in paramiko always returns the return code of the first command executed over invoke_shell

Bug #893438 reported by Samir
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
paramiko
New
Undecided
Unassigned

Bug Description

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\n with ls -al file_not_exist;exit\n 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\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()

This should print the return code of each command. Please let me know if I am doing wrong somewhere.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.