pty Functions

function pty/openpty [flags]

Equivalent to 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 (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.

function pty/forkpty

Equivalent to forkpty(3)

Return:

see below

Rtype:

list

Raises ^system-error:

forkpty calls pty/openpty then forks and returns a tuple of (pid mfd) for the Process ID returned from 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.

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 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 (libc/struct-termios)

See also

libc/tcsetattr to reset the terminal mode

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 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.

Last built at 2024-12-21T07:10:43Z+0000 from 62cca4c (dev) for Idio 0.3.b.6