Skip to content

Instantly share code, notes, and snippets.

@koba-ninkigumi
Created April 11, 2012 15:37
Show Gist options
  • Save koba-ninkigumi/2360087 to your computer and use it in GitHub Desktop.
Save koba-ninkigumi/2360087 to your computer and use it in GitHub Desktop.
pexpectのサンプル
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from pexpect import *
log = file('mylog.txt','w')
c = spawn('/bin/bash')
c.expect_exact('$')
c.sendline('ls')
c.logfile = log
c.expect_exact('$')
c.logfile = None
c.logfile_read = sys.stdout
c.sendline('pwd')
c.expect_exact('$')
c.sendline('cd ~/Desktop')
c.expect_exact('$')
c.sendline('pwd')
c.expect_exact('$')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment