Pexpect Documentation - Read the Docs

Pexpect Documentation

Release 4.8

Noah Spurrier and contributors

Sep 12, 2023

Contents

1

Installation

1.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

3

2

API Overview

2.1 Special EOF and TIMEOUT patterns . .

2.2 Find the end of line ¨C CR/LF conventions

2.3 Beware of + and * at the end of patterns .

2.4 Debugging . . . . . . . . . . . . . . . .

2.5 Exceptions . . . . . . . . . . . . . . . .

2.6 Pexpect on Windows . . . . . . . . . . .

3

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

5

6

6

7

8

8

9

API documentation

3.1 Core pexpect components . . . . . . . . . . . . . .

3.2 fdpexpect - use pexpect with a file descriptor . . . .

3.3 socket_pexpect - use pexpect with a socket . . . . .

3.4 popen_spawn - use pexpect with a piped subprocess

3.5 replwrap - Control read-eval-print-loops . . . . . . .

3.6 pxssh - control an SSH session . . . . . . . . . . . .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

11

11

23

24

25

26

27

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

4

Examples

33

5

FAQ

35

6

Common problems

6.1 Threads . . . . . . . . . . . . . . . . . . .

6.2 Timing issue with send() and sendline() . .

6.3 Truncated output just before child exits . .

6.4 Controlling SSH on Solaris . . . . . . . .

6.5 child does not receive full input, emits BEL

.

.

.

.

.

39

39

39

40

40

40

7

History

7.1 Releases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7.2 Moves and forks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

41

41

47

8

Indices and tables

49

Python Module Index

51

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

i

Index

ii

53

Pexpect Documentation, Release 4.8

Pexpect makes Python a better tool for controlling other applications.

Pexpect is a pure Python module for spawning child applications; controlling them; and responding to expected

patterns in their output. Pexpect works like Don Libes¡¯ Expect. Pexpect allows your script to spawn a child application

and control it as if a human were typing commands.

Pexpect can be used for automating interactive applications such as ssh, ftp, passwd, telnet, etc. It can be used to

automate setup scripts for duplicating software package installations on different servers. It can be used for automated

software testing. Pexpect is in the spirit of Don Libes¡¯ Expect, but 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. The Pexpect interface was designed to be easy to

use.

Contents:

Contents

1

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download