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
11
votes
1 answer

Extracting stderr from pexpect

My question is simple: Can I expect() to see certain output on stderr using pexpect? It seems pexpect.spawn() can only be used to expect output on stdout. Utopian example: import pexpect child = pexpect.spawn(...) child.expect("hi",…
Edd Barrett
  • 3,425
  • 2
  • 29
  • 48
10
votes
4 answers

how to get console output from a remote computer (ssh + python)

I have googled "python ssh". There is a wonderful module pexpect, which can access a remote computer using ssh (with password). After the remote computer is connected, I can execute other commands. However I cannot get the result in python again.…
stanleyxu2005
  • 8,081
  • 14
  • 59
  • 94
10
votes
2 answers

Is there an implementation of 'expect' or an expect-like library that works in python3?

I would like to use an expect-like module in python3. As far as I know, neither pexpect nor fabric work with python3. Is there any similar package I can use? (If no, does anyone know if py3 support is on any project's roadmap?) A perfectly…
belacqua
  • 543
  • 4
  • 18
9
votes
3 answers

How to capture inputs and outputs of a child process?

I'm trying to make a program which takes an executable name as an argument, runs the executable and reports the inputs and outputs for that run. For example consider a child program named "circle". The following would be desired run for my…
Asocia
  • 5,935
  • 2
  • 21
  • 46
9
votes
3 answers

pexpect timeout is not being used, only the default of 30 is being used

I'm trying to do a lengthy operation but pexpect with the timeout argument doesn't seem to change the length of time before the timeout exception gets fired. Here is my code: child = pexpect.spawn('scp file user@:/temp', timeout=300) whichMatched =…
darrickc
  • 1,872
  • 6
  • 27
  • 38
9
votes
3 answers

Differences between subprocess module, envoy, sarge and pexpect?

I am thinking about making a program that will need to send input and take output from the various aircrack-ng suite tools. I know of a couple of python modules like subprocess, envoy, sarge and pexpect that would provide the necessary…
bananamana
  • 485
  • 1
  • 9
  • 19
8
votes
1 answer

How to use paramiko with pexpect?

I successfully open an ssh connection with paramiko. As i have want to use pexpect for automatic interaction with the system on the remote end, I would like to to pass the paramiko connection to pexpect.fdpexpect.fdspawn, but the two don't fit…
8
votes
2 answers

How to determine the exit status code of a command send by pexpect

In the following code snippet, how do I find the exit code of make? Specifically, I need to know if make has failed or succeeded. Thanks for any inputs. process = pexpect.spawn("/bin/bash") process.expect("make\r")
doon
  • 2,311
  • 7
  • 31
  • 52
8
votes
1 answer

Why is Pexpect intermittently hanging (not detecting EOF) after executing certain commands?

Context: I have some code written using pexpect, whose job is to give "live" output of a command. I.e. print something out when a command generates some output, or soon after, rather than waiting until the command completes and then interacting with…
Zac B
  • 3,796
  • 3
  • 35
  • 52
7
votes
2 answers

how to use pexpect to get spontaneous output of subprocess in python

This is related to my another post multithreading issue with wx.TextCtrl (or underlying GTK+), which after correction with calling GUI interactions from primary thread, I find it again comes to the pipe block buffering problem. so How to get…
pepero
  • 7,095
  • 7
  • 41
  • 72
7
votes
5 answers

Pexpect, running ssh-copy-id is hanging when trying to spawn a second process

I'm doing a Python script where I need to spawn several ssh-copy-id processes, and they need for me to type in a password, so i'm using PExpect. I have basically this: child = pexpect.spawn('command') child.expect('password:') child.sendline('the…
Daniel Magliola
  • 30,898
  • 61
  • 164
  • 243
7
votes
2 answers

Is there autoexpect for pexpect?

I would like to generate Python Expect (pexpect) code automatically, does something like autoexpect exist for pexpect?
Jed Daniels
  • 24,376
  • 5
  • 24
  • 24
7
votes
2 answers

How to set explicitly the terminal size when using pexpect

I have a ncurses app that checks terminal size at startup and exits immediately if it doesn't fit. In Linux, the default size is 80x24, this app requires at least 25. The fix is easy, I'm just resizing the terminal emulation window (in X) before…
JS_is_bad
  • 369
  • 4
  • 8
7
votes
1 answer

Print and pexpect logging

I have a bit of a code that uses pexpect to control a process and some prints in the code. The main goal (in this question) is to have the pexpect output and prints logged into some log file. The problem I ran into is that the pexpect lines (data…
ilya1725
  • 4,496
  • 7
  • 43
  • 68
7
votes
3 answers

pexpect setecho not working

I am trying to telnet to Cisco Router and give commands using pexpect. Its working, but the sendline() repeats in the output. even after using setecho to False. Code is: ''' Created on Nov 19, 2012 @author: Amit Barik ''' import pexpect hostname…
amulllb
  • 3,036
  • 7
  • 50
  • 87
1
2
3
54 55