Drush commands not executing using Paramiko

我发布了有关使用Paramiko收到的持续错误消息的上述问题。我认为这与我的下一个问题无关,但可能与之相关。

我可以使用Paramiko通过SSH成功​​连接到服务器。我可以执行ls或pwd之类的命令。我似乎无法做的是更改目录。例如,我可以发送命令“cd ..”,但是当我跟进“pwd”时,它表明我尚未更改目录。它仅列出我登录时所在的初始目录。

>>> stdin, stdout, stderr = myssh.exec_command("pwd")
>>> stdout.readlines()
['/big/dom/home/myid\n']
>>> stdin, stdout, stderr = myssh.exec_command("cd ../")
>>> stdout.readlines()
[]
>>> stdin, stdout, stderr = myssh.exec_command("pwd")
>>> stdout.readlines()
['/big/dom/home/myid\n']
>>>

我误会了这里发生了什么吗?我应该不能更改目录吗?或者,如果可以的话,是否应该以其他方式而不是使用exec_command?

最佳答案

这个家伙想通了:http://www.vertigrated.com/blog/2010/02/python-remote-ssh-with-paramiko/

您只需要使用一个exec_command发送多个命令,例如:

myssh.exec_command('cd ..; pwd')

然后stdout.readlines()将返回您更改到的目录。

关于python - 如何使用Paramiko更改目录?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8932862/

10-09 17:29
查看更多