client = paramiko.SSHClient()
stdin, stdout, stderr = client.exec_command(command)
Is there any way to get the command return code?
It's hard to parse all stdout/stderr and know whether the command finished successfully or not.
client = paramiko.SSHClient()
stdin, stdout, stderr = client.exec_command(command)
Is there any way to get the command return code?
It's hard to parse all stdout/stderr and know whether the command finished successfully or not.
SSHClient is a simple wrapper class around the more lower-level functionality in Paramiko. The API documentation lists a recv_exit_status() method on the Channel class.
A very simple demonstration script:
Much easier example that doesn't involve invoking the channel class directly:
In my case, output buffering was the problem. Because of buffering, the outputs from the application doesn't come out non-blocking way. You can find the answer about how to print output without buffering in here: Disable output buffering. For short, just run python with -u option like this:
> python -u script.py
Thanks for JanC, I added some modification for the example and tested in Python3, it really useful for me.