I’m fairly new to python (3 hours in tbh) and I’m tryin to write a function that is able to connect to a remote server and then execute those commands.
As stated, I’m using ssh2-python.
This code works perfectly… whenever I forward a command that has stdout.
For example running: command_exec(‘echo “hey”’) will work perfectly!
But, running something like: command_exec(‘cd /usr/local/folder/’) will get stuck…
So I’ve figured out the issue: if a command that is forwarded doesn’t return any response (doesn’t have stdout), the function will get stuck.
I’ve tried finding a solution, but to no avail.
Worth mentioning: I don’t want to set timeout on a command, because there are some commands that I’m gonna execute on the remote server that might take a while, so setting a timeout would be a huge mistake.
Is there any solution to this?
It may also be able to help you with your timing issue; if you end your command with somehting meaningful (echo command1 for command 1), and wait until you read an output that says “command1”, you know the command is finished (as long as it’s not asynchronous, anyway)