Questions tagged [pexpect]

Pexpect is a pure Python module that reads the output of a program and sends input to that program based on output patterns. It can be used to automate interactions with interactive programs. It is inspired by the classic TCL expect program.

Pexpect is a pure Python module for controlling and automating other programs. It

Pexpect is similar to the Don Libes Expect system in TCL, but with a different interface that is intended to be easier to understand.

Pexpect is basically a pattern matching system. It runs programs and watches output. When the output matches a given pattern Pexpect can respond by sending input to the program. Pexpect can be used for automation, testing, and screen scraping of interactive programs. From the project description:

Pexpect can be used for automating interactive console applications such as ssh, ftp, passwd, telnet, etc. It can also be used to control web applications via lynx, w3m, or some other text-based web browser. Pexpect is pure Python. Unlike other Expect-like modules for Python Pexpect does not require TCL or Expect nor does it require C extensions to be compiled. It should work on any platform that supports the standard Python pty module.

Resources

820 questions
0
votes
1 answer

CPython doesn't interact well with spawned tty terminals on Windows

Everytime I try to use winpexpect to spawn terminal (eg: openssh, ssh). if I do winpexpect.winspawn('ssh ...') I am met with "Pseudo-terminal will not be allocated because stdin is not a terminal.". If I force a terminal using…
Zombies
  • 25,039
  • 43
  • 140
  • 225
0
votes
1 answer

Need to make Subprocess communication better

I'm a new bie to python programming and programming as well. so kindly excuse if this sound to be a basic question. I'm developing a tool which on course performs make clean and make on git. I'm using subprocess module for running these make…
user596922
  • 1,501
  • 3
  • 18
  • 27
0
votes
1 answer

Default parameter in python with objects

I know I can define default parameters in python, but can I do so with objects? For example, I'd like to work with a p.expect object: def exitDevice(ip, m='', sendExit=True): if sendExit: m.send('exit') print "left device", ip Is…
WildBill
  • 9,143
  • 15
  • 63
  • 87
0
votes
4 answers

Python / Pexpect before output out of sync

I'm using Python/Pexpect to spawn an SSH session to multiple routers. The code will work for one router but then the output of session.before will get out of sync with some routers so that it will return the output from a previous sendline. This…
user1440494
  • 1
  • 1
  • 2
0
votes
1 answer

python pexpect will not work with a dynamic value

So I've got a program that will ssh on to a remote server and start an iperf sever of that end. When thats running it will iperf that sever from the client side. It works fine when I give the IP address statically for example: …
Paddy
  • 195
  • 1
  • 2
  • 10
0
votes
2 answers

Using pexpect to automate a manage.py syncdb dialogue

I am trying to use pexpect to automate this dialogue. Also below is the python program using pexpect. When I run the code...it waits for input at "Would you like to create one now? (yes/no):" then timesout with an error. It is expecting a yes or…
Tampa
  • 75,446
  • 119
  • 278
  • 425
-1
votes
2 answers

How do I fix Issue running pexpect-serial example

Pexpect serial https://pypi.org/project/pexpect-serial/ throwing an exception while running example. This in on windows. How do I fix? import serial from pexpect_serial import SerialSpawn Traceback (most recent call last): File "", line 1, in File…
Sblu
  • 43
  • 8
-1
votes
1 answer

Python: communication between an app and terminal which is asking for Admins password

I’m trying to accomplish the following but no luck, any suggestions? ⇒ My app will run a command that requires admin’s password, if you run the command in Terminal, the command will stop asking for the password, however, if you run it within Python,…
-1
votes
1 answer

python pexpect type string code i terminal app

I am tring to use a terminal application from python, after run app, this app ask to imput same words. this is my curent code : import pexpect import sys child = pexpect.spawn("./helium-wallet create basic --seed mobile") child.logfile_read =…
Lucian Blaga
  • 137
  • 2
  • 7
-1
votes
1 answer

Problem stripping characters from a pexpect query

I'm testing a python script to retrieve the software version from Cisco gear. The script works fine connecting to the remote device and obtaining the information required. The problem starts when I try to filter some unwanted information from…
olg32
  • 305
  • 2
  • 6
  • 19
-1
votes
1 answer

How to extract particlar message from a vast displayed output using python regular expression?

Firstly in the code, i would like to know How can i add a for loop for CH (1-11) instead of writing for every number Also how to extract SUCCESS and FAILED message from the output (reference) For example i want the output as CH1 : Failed CH2:…
Shishira
  • 1
  • 3
-1
votes
1 answer

AttributeError: 'module' object has no attribute 'spawn'

here is my code #!/usr/bin/env python import pexpect obj=pexpect.spawn('ftp localhost') print id.expect_exact('Name') i am using kali linux and have also installed pexpect.i m also running an vsftpd ftp server.This is the error thats comes up when…
-1
votes
2 answers

Python Function Works just fine but doesnt work when for looped

So I Created this function that changes a UNIX users password, and it works just fine but I want to for loop a list of users to change every users password. But the for loop doesn't work in the function, When i assign a variable for the same user in…
-1
votes
1 answer

Having trouble passing 2 variables to pexpect; string indices must be integers, not str

trying to pull data from a wireless controller. the command is show ap auto-rf band can be either 802.11a 802.11b or 802.11-abgn ap-name is arbitrary sample output: (Cisco Controller) >show ap auto-rf 802.11-abgn Hallway38 Number Of…
-1
votes
2 answers

GUI freezes on cmd run but not through Pycharm

So I've been looking at this for quite some time and can't figure this problem out. The goal here is to have it display realtime results line by line from the cmd/ terminal into the tkinter ScrolledText/Text widget, which it does except when ran…
BoobyTrap
  • 967
  • 7
  • 18