Skip to content

Instantly share code, notes, and snippets.

@chzyer
Created January 11, 2013 06:11
Show Gist options
  • Save chzyer/4508354 to your computer and use it in GitHub Desktop.
Save chzyer/4508354 to your computer and use it in GitHub Desktop.
python命令行预处理实例[ssh远程连接]
import pexpect
ssh = pexpect.spawn('ssh localhost') #建立新线程,执行"通过ssh连接本地"
ssh.expect('.*password:') #正则匹配输入密码提示,匹配才继续执行
ssh.sendline("123456") #输入密码
ssh.interact() #执行
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment