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.
def command_exec(command): print('Executing command: ' + command) channel.write(command + '\n') print('Wrote command!') size, data = channel.read() print(size) print(data.decode())
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?