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

python pexpect sendcontrol key characters

I am working with pythons pexpect module to automate tasks, I need help in figuring out key characters to use with sendcontrol. how could one send the controlkey ENTER ? and for future reference how can we find the key characters? here is the code…
SSSSSam
  • 113
  • 1
  • 2
  • 8
6
votes
1 answer

`pipenv install` timing out on RPi

I'm trying to bring up [pipenv][1] on a Raspberry Pi Zero W. The symptom I'm seeing is that pexpect times out when trying to create a tutorial project. Admittedly, the RPi is a small machine, but I was monitoring memory usage and swap space during…
fearless_fool
  • 33,645
  • 23
  • 135
  • 217
6
votes
1 answer

Reading serial output from Pyserial doesnt work reliably

I am connecting to device using code blow on MacOS and out of 100 times this code would make connection only 1 or two times and dones't respond(since there is no timeout) rest of the times. ser = serial.Serial(port="/dev/xyz",timeout = None,…
bruceparker
  • 1,235
  • 1
  • 17
  • 33
6
votes
1 answer

Python pexpect : fdpexpect + pyserial == timeout does not work?

I am trying to use pexpect on serial port. I use fdpexpect as suggested. But I noticed that expect() does not obey timeout. Instead, the EOF happens. ser = serial.Serial(sys.argv[1], 9600) fd = fdpexpect.fdspawn(ser.fd) fd.send('%s\r' % username) i…
some user
  • 876
  • 1
  • 12
  • 26
6
votes
1 answer

How to prevent pexpect from echoing the password?

By default, pexpect.spawn() would not output anything. But when I specify logfile=sys.stdout it'll also echo the password (e.g. for ssh). So how can I see the real time interaction with the spawned process without the password being echoed (just…
pynexj
  • 19,215
  • 5
  • 38
  • 56
6
votes
6 answers

Verify a file exists over ssh

I am trying to test if a file exists over SSH using pexpect. I have got most of the code working but I need to catch the value so I can assert whether the file exists. The code I have done is below: def VersionID(): ssh_newkey = 'Are you…
chrisg
  • 40,337
  • 38
  • 86
  • 107
6
votes
1 answer

Parsing pexpect output

I'm trying to parse in real time the output of a program block-buffered, which means that output is not available until the process ends. What I need is just to parse line by line, filter and manage data from the output, as it could run for…
peluzza
  • 329
  • 2
  • 4
  • 11
6
votes
3 answers

EOF when using pexpect and pxssh

I'm trying to run the code in the Interacting with SSH Through Pexpect and Brute Forcing SSH Passwords with Pxssh sections from Chapter 2 of Violent Python. Using both child.expect() and pxssh I get similar EOF errors. Running these commands from…
mbaytas
  • 2,676
  • 7
  • 26
  • 37
6
votes
3 answers

python pexpect: SSHing then updating the date

I have finally have my python pexpect script working except for the most important part updating the date! I am able to SSH in the box but my second command does not execute properly. I have been banging my head on the wall trying to figure out why.…
WorkerBee
  • 683
  • 3
  • 11
  • 22
5
votes
1 answer

`stdout` is empty when passing data to `stdin` via `subprocess`, but contains the expected output when input is entered manually?

So I'm working on trying to receive chess move data from the Leela Chess Zero engine. I am already done with all of the UI and other parts of the backend, and this is the last thing I need to implement. Unfortunately, I seem to have overestimated…
Vlad
  • 163
  • 1
  • 1
  • 8
5
votes
0 answers

Python Multiprocessing fails in first attempt of command execution in connected devices, From second attempt onwards passed in all subprocesses

I'm trying to run bunch of linux commands on multiple devices parallely using python multiprocessing module. script is able to connect to multiple devices serially and starts executing the linux commands parallely. the script fails in the first…
5
votes
0 answers

stanford corenlp python error with pexpect

I am trying to run the corenlp.py from stanford corenlp python package. When I run it I am getting this error: Traceback (most recent call last): File "corenlp.py", line 592, in main() File "corenlp.py", line 580, in main nlp =…
ida
  • 1,011
  • 1
  • 9
  • 17
5
votes
1 answer

How to run the pexpect script for terminal with colored text

Pexpect works fine when I run in interactive sessions but if it has colored text then its not matching only the text,it's matching the text along with ansi colors. The regex for this is very complicated and big. Can someone suggest me anything how…
user7369931
  • 193
  • 1
  • 11
5
votes
4 answers

Pexpect - silence ssh connection output

I'm using a simple pexpect script to ssh to a remote machine and grab a value returned by a command. Is there any way, pexpect or sshwise I can use to ignore the unix greeting? That is, from child = pexpect.spawn('/usr/bin/ssh %s@%s' %…
Joao Figueiredo
  • 3,120
  • 3
  • 31
  • 40
5
votes
1 answer

pexpect - multiple expects

Is it possible to "wait" for different answers from an expect command at the same time? E.g: child.expect('first', 'second') And if YES, how can differentiate which one has triggered it?
Kaguei Nakueka
  • 993
  • 2
  • 13
  • 34
1 2
3
54 55