pty, ptytio

pty, ptytio — run programs in a pseudo-tty.

Syntax

pty (program, arguments...? = nil)
ptytio (termios, program, arguments...? = nil)

		

Arguments

program

A string containing the name of the program to be executed.

arguments

A string containing any command-line arguments for the program.

termios

A termios structure.

Returns

A list of:

(process_id file_for_stdin file_for_stdout file_for_stderr pty_name)

Where:

process_id

The process ID of the program called.

file_for_stdin

A pointer to the file used for STDIN.

file_for_stdout

A pointer to the file used for STDOUT.

file_for_stderr

A pointer to the file used for STDERR.

pty_name

The path and filename of this pseudo-tty, as a string.

Description

These functions run programs in a pseudo-tty. A Gamma program can read from either program's standard output by issuing a read or read_line call on file_for_stdout. The process can be reaped using wait.

The ptytio function is the same as pty, but the first argument is a termios structure. This is useful if particular terminal characteristics are required on the pty. The termios structure is only available through the gammatios.so dynamic library.

Example

This example calls pty on the following test program, called testpty.g:

#!/usr/cogent/bin/gamma
princ("Test output.\n");
princ(cadr(argv),"\n");
    

Here we call pty in interactive mode, and then read the output:

Gamma> ptylist = pty("testpty.g", "Argument");
(4760 #<File:"testpty.g-stdin"> #<File:"testpty.g-stdout">
    #<File:"testpty.g-stderr"> "/dev/ptyp0")
Gamma> read_line(caddr(ptylist));
"This software is free for non-commercial use, and no valid commercial license"
Gamma> read_line(caddr(ptylist));
"is installed.  For more information, please contact info@cogent.ca."
Gamma> read_line(caddr(ptylist));
"Test output."
Gamma> read_line(caddr(ptylist));
"Argument"
Gamma>