【发布时间】:2010-04-30 18:20:14
【问题描述】:
我正在尝试使用 pexpect SSH 进入计算机,但我不想返回到原来的计算机。我的代码是:
#!/usr/bin/python2.6
import pexpect, os
def ssh():
# Logs into computer through SSH
ssh_newkey = 'Are you sure you want to continue connecting'
# my ssh command line
p=pexpect.spawn('ssh build@10.51.11.10')
i=p.expect([ssh_newkey,'password:',pexpect.EOF])
p.sendline("password")
i=p.expect('-bash-3.2')
print os.getcwd()
ssh()
这允许我通过 ssh 进入计算机,但是当我运行 os.getcwd() 时,pexpect 已将我返回到原始计算机。你看我想 ssh 到另一台计算机并使用他们的环境而不是使用 pexpect 拖动我的环境。任何人都可以建议如何让这个工作或替代方式。
谢谢
【问题讨论】: