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
-1
votes
2 answers

Python pexpect not recognizing "More" on Cisco

Trying to login to a Cisco router. It's not sending the right commands at the "--More--" prompt. I think it might have to do on what I'm sending. I need to have a space command sent when it gets to the More prompt. It will send a "\" character, but…
Dan
  • 359
  • 5
  • 17
-1
votes
1 answer

Python module 'spawn'. Module object is not callable

This is my code: import pexpect import spawn host = 'xx.xx.xx.xx' userName = 'akshay' password = 'xxxxxxxxxxxxxx' **child = spawn('ssh %s@%s' %(userName, host))** child.setwinsize(1000,200) child.expect(['password'], timeout=5) Here I'm trying to…
-1
votes
1 answer

Filtering pexpect output

I have a Cisco router and I need to know which interface is used for LAN. This is the show interface description output: R1#sho int desc Interface Status Protocol Description Em0/0 admin down …
human374
  • 113
  • 4
-1
votes
1 answer

re.search not matching the byte string

I have a string object got from pexpect's session.before. From this I am trying re.search for getting the device id using the below regular expression. But it is not matching. print (str(sess.before)) b'\r\n* daemon not running. starting it now on…
Ashwin
  • 993
  • 1
  • 16
  • 41
-1
votes
2 answers

Pexpect+pxssh handling of long strings

I am using pexpect+pxssh to communicate with a remote server. Somme commands can be a bit long and the following code does not work: import pxssh channel = pxssh.pxssh() channel.login('192.168.93.129', 'tester', 'tester', 22,…
SebE
  • 1
  • 2
-1
votes
1 answer

pexpect: How to match the string

I am trying to automate the CLI menu on Linux system where at many points i have to provide based the condition. i have prompt with ': ', I am trying to match (111.222.333.444)the string (printed in child.before) below, 111.222.333.444 : if the…
tgcloud
  • 857
  • 6
  • 18
  • 37
-1
votes
1 answer

running adb with python: executing a program and ending it

I am trying to perform adb interactions through python code. I have an endless executable on the android device which i would like to start and after 10 seconds kill it. right now, i can get the program to start but cannot kill it other the manually…
TamirE
  • 3
  • 2
-1
votes
2 answers

Python Script Pexpect SSH

I'm trying to do a Python script (with a loop) to connect in SSH,it works if everything is good ( password and route) but stop when it's not working(wrong password or no routes to host ).Here is the important part of the script, how can I control if…
77140B
  • 41
  • 6
-1
votes
1 answer

Pexpect.spawn ssh and cron (Solaris)

I am having problems using cron to run a pexpect script on Solaris 10 that will ssh to other devices. The devices I am connecting to are networking elements which will accept ssh connections using user/pass (but I cannot reconfigure them). I have…
weldja
  • 1
-1
votes
2 answers

pexpect kind of operation with ansible

I am looking to automate an interactive install process with ansible. This install does not have a silent install option or does not take command line arguments for the interactive questions. The question involve setting a folder location, making…
ash
  • 781
  • 1
  • 9
  • 20
-1
votes
3 answers

How to control links2 with Python

How can I execute links2 to open a web page and locate and click a text link with Python? Is pexpect able to do it? Any examples are appreciated.
jack
  • 17,261
  • 37
  • 100
  • 125
-1
votes
1 answer

Using pexpect to control kpcli

I am trying to automate ssh connectivity using keepassdb and I am just starting out the script to interrogate the keypass kpcli shell. I want it to print out the result at the end. # -*- coding: utf -*- import os,sys import pexpect global…
Paul Dawson
  • 1,332
  • 14
  • 27
-1
votes
1 answer

Can two strings arguments be passed to a python dict() built in function?

I have a loop i would like to build a dictionary from. The part of the code I'm having trouble with is that both the key and the value are strings. I cannot convert the IP variable back string into a int nor is it a float. Here is the method from…
jonnymac
  • 43
  • 6
-1
votes
1 answer

pexpect parse router output

I've got a couple of pexpect lines to log onto a cisco router, and issue the show arp command. I then exit the router, having stored the data into the variable myARP (myARP=child.before) When I then try and loop over the object (for lines in myARP:…
user225882
  • 53
  • 1
  • 1
  • 4
-2
votes
1 answer

Ansible expect adds other character to response and does not enter it

I'm trying to install no-ip's Dynamic Update Client. I'm using the expect module to answer every prompt, but each time the script ask for my password, it adds another character and does not enter the password (the command exceeded timeout). Here is…
tholeb
  • 174
  • 3
  • 13
1 2 3
54
55