Can I use Expect on Windows without installing Cygwin?
Asked Answered
C

6

12

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

Contreras answered 25/6, 2009 at 9:6 Comment(0)
S
17

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.

Sinistrous answered 25/6, 2009 at 9:52 Comment(2)
@Symmetric: you've changed the link to point to winpexpect. But wexpect is a different module.Remissible
@J.F.Sebastian: good spot, those old links were broken so I wasn't able to find much about wexpect. Fixed.Bract
C
6

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

https://github.com/geertj/winpexpect

Catharinecatharsis answered 19/7, 2010 at 21:21 Comment(0)
P
4

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
Pronounced answered 18/5, 2016 at 7:52 Comment(1)
You can install it but note, that there is no native support for windows. There are issues around windows usage: pexpect.readthedocs.io/en/stable/overview.html#windowsJodyjoe
P
2

Use pexpect https://github.com/pexpect/pexpect

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

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

Prey answered 25/6, 2009 at 9:52 Comment(0)
V
2

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

Hopefully it will be merged upstream soon.

Vivienviviene answered 5/4, 2010 at 23:47 Comment(0)
B
0

I've successfully used Pexpect under Cygwin. For now there is no other way due to POSIX compatibility problems under Windows.

Another thing: WExpect works like Pexpect, in fact it requires Cygwin! At this point, PExpect is a better choice.

Blamable answered 24/7, 2015 at 14:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.