View source for Pexpect

From Openmoko

Jump to: navigation, search

You do not have permission to edit this page, for the following reasons:

  • The action you have requested is limited to users in the group: Administrators.
  • You must confirm your email address before editing pages. Please set and validate your email address through your user preferences.

You can view and copy the source of this page:

Template used on this page:

Return to Pexpect.

Personal tools

Pexpect is a pure Python module for spawning child applications; controlling them; and responding to expected patterns in their output. Pexpect allows your script to spawn a child application and control it as if a human were typing commands. Pexpect can be used for automating interactive applications such as ssh, ftp, passwd, telnet, etc. It can be used to a automate setup scripts for duplicating software package installations on different servers. It can be used for automated software testing. The Pexpect interface was designed to be easy to use.


Download the current version from sourceforge site.

installing pexpect

  1. download pexpect-2.1.tar.gz
  2. tar zxf pexpect-2.1.tar.gz
  3. cd pexpect-2.1
  4. python install do this as root


Under the pexpect-2.1 directory you should find the examples directory. This is the best way to learn to use Pexpect. See the descriptions of Pexpect Examples.

API document

  • pexpect This is the main module that you want.
  • pxssh Pexpect SSH is an extension of 'pexpect.spawn' that specializes in SSH.

the following are experimental extensions to Pexpect

  • fdpexpect fdpexpect extension of 'pexpect.spawn' that uses an open file descriptor.
  • SCREEN This represents a virtual 'screen'.
  • ANSI This parses ANSI/VT-100 terminal escape codes.
  • FSM This is a finite state machine used by ANSI.

How to use in neo

build package

Download BitBake recipe from here. Using MokoMakefile tool train:

  • copy this bitbake recipe to python package folder
cp $OMDIR/openembedded/packages/python
  • use bitbake to build pexpect
bitbake python-pexpect
  • it generates the package files to this folder


Using SCP to upload the ipk file to neo

  • install pexpect to card memory, reference from here
ipkg install -d card armv4tpython-pexpect_2.1-r0_armv4t.ipk
  • solve the PYTHON path problem
ipkg files python-pexpect
ipkg files python-io
export PYTHONPATH="/media/card/ipkg/usr/lib/python2.5/site-packages/: \
  • verify the pexpect module
python -c "import pexpect"
  • some examples:
child = pexpect.spawn('libgsmd-tool -m shell')