|Line 56:||Line 56:|
Revision as of 08:35, 26 November 2007
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.
- download pexpect-2.1.tar.gz
- tar zxf pexpect-2.1.tar.gz
- cd pexpect-2.1
- python setup.py 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.
- 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
- copy this bitbake recipe to python package folder
cp python-pexpect_2.1.bb $OMDIR/openembedded/packages/python
- use bitbake to build 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/: \ /media/card/ipkg/usr/lib/python2.5/lib-dynload/:/media/card/ipkg/usr/lib/python2.5/"
- verify the pexpect module
python -c "import pexpect"
- some examples:
child = pexpect.spawn('libgsmd-tool -m shell') child.sendline('O') child.expect(['Power-On','ERROR','OK'])
|NOTE: we may consider to use pexpect to do some auto tests for GSM functions|