【发布时间】:2011-06-01 15:25:03
【问题描述】:
def exec_command(self, command, bufsize=-1):
#print "Executing Command: "+command
chan = self._transport.open_session()
chan.exec_command(command)
stdin = chan.makefile('wb', bufsize)
stdout = chan.makefile('rb', bufsize)
stderr = chan.makefile_stderr('rb', bufsize)
return stdin, stdout, stderr
在 paramiko 中执行命令时,它总是会在您运行 exec_command 时重置会话。 当我运行另一个 exec_command 时,我希望能够执行 sudo 或 su 并且仍然拥有这些权限。 另一个示例是尝试 exec_command("cd /") 然后再次运行 exec_command 并将其放在根目录中。我知道您可以执行类似 exec_command("cd /; ls -l") 的操作,但我需要在单独的函数调用中执行此操作。
【问题讨论】: