I've been trying to find a solution and have looked here and here.
Here is my code:
def sshRunCommand(self, command, print_stdout=True, print_stderr=True):
def run_exec_command_thread(command):
(stdin, stdout, stderr) = self.client.exec_command(command)
# Appends command to always change to the home directory first
x = "cd /home/" + self.username + "/; " + command
# Locally output an terminal-esque command look-a-like
if print_stdout:
print self.username + "@" + self.payloadd + ":" + x
exec_command_thread = Thread(
target=run_exec_command_thread,
args=(x,))
exec_command_thread.daemon = True
exec_command_thread.start()
while exec_command_thread.isAlive():
a = stdout.readlines()
for b in a:
print b
I want to make stdin
, stdout
, & stderr
in the nested function run_exec_command_thread
to be shared with it's parent function. I'm using Python 2.7 so I can't use nonlocal
. I don't know how to share the variables between them for this specific case because I don't know how to implement a dict solution in this case because the object type is a paramiko.channel.ChannelFile
. I'm hoping somebody can get me going in the right direction.