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')
相关文章
相关标签/搜索