paramiko 下 SSH execute_command cd命令無效的問題

使用execute_command執行cd命令後,使用pwd查看,發現仍是在原先的目錄下ssh

stdin, stdout, stderr = conn.exec_command('cd /test/')
stdin, stdout, stderr = conn.exec_command('pwd')

排查了下,緣由是exec_command每次執行後,不會保存會話。
把要執行的多條命令放在一個字符串中,使用;分隔。以下:code

stdin, stdout, stderr = ssh.exec_command('cd /test/;pwd')
相關文章
相關標籤/搜索