Pexpect is a Pure Python Expect-like module
Pexpect makes Python a better tool for controlling other applications.
Pexpect is a pure Python module for spawning child applications; controllingthem; and responding to expected patterns in their output. Pexpect works likeDon Libes' Expect. Pexpect allows your script to spawn a child application andcontrol it as if a human were typing commands.
Python Pexpect Windows Ssh
The idea of pexpect originated from a programming language called Expect that automates interactions with programs that expose a text terminal like ftp, ssh, etc. Think of any program that opens a session that you have to exit! Prerequisites Python 2.7 or Python 3.3 or above pip install pexpect If.
Pexpect can be used for automating interactive applications such as ssh, ftp,passwd, telnet, etc. It can be used to automate setup scripts for duplicatingsoftware package installations on different servers. Chessmaster grandmaster edition download full. It can be used forautomated software testing. Pexpect is in the spirit of Don Libes' Expect, butPexpect is pure Python.
The main features of Pexpect require the pty module in the Python standardlibrary, which is only available on Unix-like systems. Some features—waitingfor patterns from file descriptors or subprocesses—are also available onWindows.
If you want to work with the development version of the source code then pleaseread the DEVELOPERS.rst document in the root of the source code tree.
Free, open source, and all that good stuff.
You can install Pexpect using pip:
PEXPECT LICENSE:
This license is approved by the OSI and FSF as GPL-compatible.
Active1 month ago
I'm trying to write a cross-platform tool that runs specific commands, expects certain output for verification, and sends certain output (like username/password) for authentication.
On Unix, I have been successful in programming a Python tool that uses the
pexpect
library (via pip install pexpect
). This code works perfectly and is exactly what I am trying to do. I've provided a small excerpt of my code for proof-of-concept below:I tried running the same source on Windows (changing
/usr/bin/ctf
to c:/ctf.exe
) and I receive an error message:According to the
pexpect
documentation:pexpect.spawn
and pexpect.run()
are not available on Windows, as they rely on Unix pseudoterminals (ptys). Cross platform code must not use these.That led me on my search for a Windows equivalent. I have tried the popular
winpexpect
project here and even a more recent (forked) version here, but neither of these projects seem to work. I use the method:only to sit and watch the Command Prompt do nothing (it seems as though it's trapped inside the
ConfiqureConfiqurewinspawn
method). I was wondering what other means I could go about programming a Python script to interact with the command line to achieve the same effect as I have been able to in Unix? If a suitable working Windows-version pexpect
script does not exist, what other means could I use to go about this?4,4661010 gold badges4848 silver badges7373 bronze badges
2 Answers
Instead of using
AK47pexpect.spawn
you can use pexpect.popen_spawn.PopenSpawn
for windows
.5,49833 gold badges2222 silver badges4242 bronze badges
Hemang BhimaniHemang Bhimani
You can use wexpect ('Windows alternative of pexpect', Python Software Foundation). It has the same functions, and it works on Windows .
James CastellsJames Castells