.. include:: ../global.rst .. idio:currentmodule:: pty pty Functions ------------- .. _`pty/openpty`: .. idio:function:: pty/openpty [flags] Equivalent to :manpage:`openpty(3)` :param flags: flags to posix_openpt, defaults to ``O_RDWR [| O_NOCTTY]`` :type flags: C/int, optional :return: see below :rtype: list :raises ^system-error: ``openpty`` returns a tuple of :samp:`({mfd} {sfd} {ptsname})` for the: * master file descriptor, `mfd` * slave file descriptor, `sfd` * slave terminal device name, `ptsname` `sfd` is an open file descriptor to `ptsname` opened with `flags`. ``O_NOCTTY`` is not available on some systems. .. _`pty/forkpty`: .. idio:function:: pty/forkpty Equivalent to :manpage:`forkpty(3)` :return: see below :rtype: list :raises ^system-error: ``forkpty`` calls :ref:`pty/openpty ` then forks and returns a tuple of :samp:`({pid} {mfd})` for the Process ID returned from :ref:`libc/fork `, `pid`, and master file descriptor, `mfd`. In the child process, the process is set to be a session leader and the slave file descriptor will be set as the controlling tty. .. _`pty/spawn`: .. idio:function:: pty/spawn [argv] Spawn a process defined by `argv` :param argv: command and arguments :type argv: list :return: see below :rtype: list :raises ^system-error: The child process will :manpage:`execve(2)` `argv`. The parent's return value is a list of: * the child Process ID * the master file descriptor * the original terminal mode for stdin (:ref:`libc/struct-termios `) .. seealso:: :ref:`libc/tcsetattr ` to reset the terminal mode .. _`pty/spawn-sync`: .. idio:function:: pty/spawn-sync (:mreader spawn-read) (:inreader spawn-read) [argv ...] Spawn a process defined by `argv` and interact with it synchronously :param argv: command and arguments :type argv: list :keyword :mreader: function to read from master device, defaults to simple internal function :type :mreader: function, optional :keyword :inreader: function to read from stdin, defaults to simple internal function :type :inreader: function, optional :return: result from :ref:`waitpid ` :rtype: list :raises ^system-error: Both `:mreader` and `:inreader` should be a function which accepts a `C/int` file descriptor as its single argument and should return a string. This function invokes a simple copy of data to and from the sub-process. .. include:: ../commit.rst