Ptyprocess API

class ptyprocess.PtyProcess(pid, fd)[source]

This class represents a process running in a pseudoterminal.

The main constructor is the spawn() classmethod.

classmethod spawn(argv, cwd=None, env=None, echo=True, preexec_fn=None, dimensions=(24, 80), pass_fds=())[source]

Start the given command in a child process in a pseudo terminal.

This does all the fork/exec type of stuff for a pty, and returns an instance of PtyProcess.

If preexec_fn is supplied, it will be called with no arguments in the child process before exec-ing the specified command. It may, for instance, set signal handlers to SIG_DFL or SIG_IGN.

Dimensions of the psuedoterminal used for the subprocess can be specified as a tuple (rows, cols), or the default (24, 80) will be used.

By default, all file descriptors except 0, 1 and 2 are closed. This behavior can be overridden with pass_fds, a list of file descriptors to keep open between the parent and the child.

class ptyprocess.PtyProcessUnicode(pid, fd, encoding='utf-8', codec_errors='strict')[source]

Unicode wrapper around a process running in a pseudoterminal.

This class exposes a similar interface to PtyProcess, but its read methods return unicode, and its write() accepts unicode.