Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1 | |
| 2 | :mod:`pty` --- Pseudo-terminal utilities |
| 3 | ======================================== |
| 4 | |
| 5 | .. module:: pty |
Benjamin Peterson | 526bec2 | 2009-10-12 01:26:07 +0000 | [diff] [blame^] | 6 | :platform: Linux |
| 7 | :synopsis: Pseudo-Terminal Handling for Linux. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 8 | .. moduleauthor:: Steen Lumholt |
| 9 | .. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il> |
| 10 | |
| 11 | |
| 12 | The :mod:`pty` module defines operations for handling the pseudo-terminal |
| 13 | concept: starting another process and being able to write to and read from its |
| 14 | controlling terminal programmatically. |
| 15 | |
Mark Dickinson | 3e4caeb | 2009-02-21 20:27:01 +0000 | [diff] [blame] | 16 | Because pseudo-terminal handling is highly platform dependent, there is code to |
Benjamin Peterson | 526bec2 | 2009-10-12 01:26:07 +0000 | [diff] [blame^] | 17 | do it only for Linux. (The Linux code is supposed to work on other platforms, |
| 18 | but hasn't been tested yet.) |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 19 | |
| 20 | The :mod:`pty` module defines the following functions: |
| 21 | |
| 22 | |
| 23 | .. function:: fork() |
| 24 | |
| 25 | Fork. Connect the child's controlling terminal to a pseudo-terminal. Return |
| 26 | value is ``(pid, fd)``. Note that the child gets *pid* 0, and the *fd* is |
| 27 | *invalid*. The parent's return value is the *pid* of the child, and *fd* is a |
| 28 | file descriptor connected to the child's controlling terminal (and also to the |
| 29 | child's standard input and output). |
| 30 | |
| 31 | |
| 32 | .. function:: openpty() |
| 33 | |
| 34 | Open a new pseudo-terminal pair, using :func:`os.openpty` if possible, or |
Benjamin Peterson | 526bec2 | 2009-10-12 01:26:07 +0000 | [diff] [blame^] | 35 | emulation code for generic Unix systems. Return a pair of file descriptors |
| 36 | ``(master, slave)``, for the master and the slave end, respectively. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 37 | |
| 38 | |
| 39 | .. function:: spawn(argv[, master_read[, stdin_read]]) |
| 40 | |
| 41 | Spawn a process, and connect its controlling terminal with the current |
| 42 | process's standard io. This is often used to baffle programs which insist on |
| 43 | reading from the controlling terminal. |
| 44 | |
| 45 | The functions *master_read* and *stdin_read* should be functions which read from |
Georg Brandl | bb75e4e | 2007-10-21 10:46:24 +0000 | [diff] [blame] | 46 | a file descriptor. The defaults try to read 1024 bytes each time they are |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 47 | called. |
| 48 | |