【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
使用execute_command执行cd命令后,使用pwd查看,发现还是在原先的目录下
stdin, stdout, stderr = conn.exec_command('cd /test/')
stdin, stdout, stderr = conn.exec_command('pwd')
排查了下,原因是exec_command每次执行后,不会保存会话。
把要执行的多条命令放在一个字符串中,使用;分隔。如下:
stdin, stdout, stderr = ssh.exec_command('cd /test/;pwd')
来源:oschina
链接:https://my.oschina.net/u/2396236/blog/3142725