2016-03-21 69 views
2

我需要通過ssh.exec_command()模擬執行一些遠程命令() 它作爲paramiko.ChanelFile對象返回元組(stdin,stdout,stderr)。模擬paramiko.SSHClient()。exec_command()

所以,我的命令輸出爲字符串(我想,exec_command()返回)以及如何使用我的輸出字符串創建ChanelFile對象的問題。

僞代碼:

def send_command(self, cmd) 
     self.client.connect(hostname=self.host, 
          username=self.user, 
          password=self.password, 
          timeout=self.timeout) 
     stdin, stdout, stderr = self.client.exec_command(cmd) 

     return stdin, stdout, stderr 

    if __name__ == '__main__': 
     stdin, stdout, stderr = report.send_command('ls -la') 
     resp = stdout.read().strip() 

所以我需要創建粗壯的是它能夠運行閱讀()方法。

回答