How do you execute multiple commands in a single session in Paramiko? (Python)

前端 未结 6 1198
礼貌的吻别
礼貌的吻别 2020-11-27 13:50
def exec_command(self, command, bufsize=-1):
    #print \"Executing Command: \"+command
    chan = self._transport.open_session()
    chan.exec_command(command)
             


        
6条回答
  •  無奈伤痛
    2020-11-27 14:08

    cmd = 'ls /home/dir'
    self.ssh_stdin, self.ssh_stdout, self.ssh_stderr = self.ssh.exec_command(cmd)
    print self.ssh_stdout.read()
    cmd2 = 'cat /home/dir/test.log'
    self.ssh_stdin2, self.ssh_stdout2, self.ssh_stderr2 = self.ssh.exec_command(cmd2)
    print self.ssh_stdout2.read()
    

提交回复
热议问题