views:

854

answers:

4

expect is a module used for spawning child applications and controlling them. I'm interested in python/ruby.

+2  A: 

use pexpect http://sourceforge.net/projects/pexpect/

"Pexpect is pure Python" so it will run anywhere, without cygwin too,

edit: pexpect depends on pty module which is currently availble only for linux, so as Nik suggested you should be using wexpect which is port of pexpect

Anurag Uniyal
+3  A: 

There is WExpect for Python.
Source files are here and last updates are from Dec 2008.

Notes in the wexpect.py file (typos unchanged and highlighting added)

Wexpect is a port of pexpext to Windows. Since python for Windows lacks the requisite modules (pty, tty, select, termios, fctnl, and resource) to run pexpect, it was necessary to create a back-end that implemented any functions that were used that relied on these modules. Wtty.py is this back-end. In the Windows world consoles are not homogeneous. They can use low level or high level input and output functions, and to correctly deal with both cases two child processes are created for instacne of Spawn, with an intermidate child that can continuously read from the console, and send that data over a pipe to an instance of wtty. Spawner.py is resposible from reading and piping data.

I've left as much code intact as I could and also tried to leave as many comments intact is possible (espicially for functions that have not been changed) so many of the comments will be misleading in their relationship to os specific functionality. Also, the functions sendcontrol and sendeof are unimplemnted at this time, as I could not find meaningful Windows versions of these functions.
additionally, consoles do not have associated fild descriptors on Windows, so the global variable child_fd will always be None.

nik
+1  A: 

The latest working version of wexpect lives at http://sage.math.washington.edu/home/goreckc/sage/wexpect/

Hopefully it will be merged upstream soon.

A: 

winpexpect is a native port of pexpect to windows. It can be found here:

http://bitbucket.org/geertj/winpexpect

Geert