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/