Can I use Expect on Windows without installing Cygwin?
winpexpect
is a native port of pexpect
to Windows. It can be found here:
https://github.com/geertj/winpexpect
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.
You can use the Windows CMD prompt.
You need to have Python installed in your Windows installation.
Open a cmd prompt and execute the below command:
C:\Users\xxx>pip install pexpect
(if you have set the Python path in a system variable)
or
C:\Users\xxx>c:\python27\scripts\pip.exe install pexpect
Collecting pexpect
Downloading pexpect-4.0.1.tar.gz (143kB)
100% |################################| 147kB 1.2MB/s
Collecting ptyprocess>=0.5 (from pexpect)
Downloading ptyprocess-0.5.1-py2.py3-none-any.whl
Building wheels for collected packages: pexpect
Running setup.py bdist_wheel for pexpect
Stored in directory: C:\Users\xxx\AppData\Local\pip\Cache\wheels\f2\65\89\09578bcd0efeabc7e2b0079cd62d3955c1477f2e55aa5031a4
Successfully built pexpect
Installing collected packages: ptyprocess, pexpect
Successfully installed pexpect-4.0.1 ptyprocess-0.5.1
The latest working version of wexpect lives at http://sage.math.washington.edu/home/goreckc/sage/wexpect/
Hopefully it will be merged upstream soon.