20

I launch a shell script from a remote Linux machine using Paramiko. The shell script is launched and execute a command make -j8. However the exec_command returns before the completion of the make.

If I launch the script on the local machine it executes correctly.

Could someone explain me this behaviour?

1 Answer 1

30

You need to wait for application to finish, exec_command isn't a blocking call.

print now(), "before call"
stdin, stdout, sterr = ssh.exec_command("sleep(10)")
print now(), "after call"
channel = stdout.channel
print now(), "before status"
status = channel.recv_exit_status()
print now(), "after status"
Sign up to request clarification or add additional context in comments.

2 Comments

weirdly, using stdout.channel.recv_exit_status() blocks my code forever
@sliders_alpha Indeed, while this answer is in principle correct, this simple implementation will hang/deadlock, if the command's output is sufficiently large. See Paramiko ssh die/hang with big output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.