Python – use Expect on Windows without installing Cygwin

expectpythonruby

Expect is a module used for spawning child applications and controlling them. I'm interested in Python and Ruby.

Best Answer

There is WExpect for Python.

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.