ptyio

## Name

ptyio — feed input to a pty and print its output

## Synopsis

`ptyio` [-t] [-T] [-r] {`subprogram`} {`args`...}

## Description

ptyio copies its input to the master side of a pty. Meanwhile, it prints all output that shows up from the master.

ptyio runs `subprogram` as a child process (not a process group leader). It supplies a "job control" pipe to `subprogram` as descriptor 9. After the pipe closes, ptyio will wait for `subprogram` to exit; then ptyio will exit with the same exit code.

If ptyio reaches EOF or sees an error on its input, it stops reading input, but it continues printing output. If ptyio sees an error on its output, it sends SIGPIPE to `subprogram` and stops writing output.

ptyio must be invoked with descriptor 4 pointing to the pty master and descriptor 5 pointing to the pty slave. It passes these descriptors to `subprogram`. It must also be invoked with environment variable `TTY` giving the name of the pty slave. It passes this variable to `subprogram`.

## Options

-t

  Attached to a tty.

  ptyio must be attached to a tty in one of the following places: descriptor 3; `/dev/tty` (i.e. controlling TTY); descriptor 2; descriptor 0; descriptor 1. Before running `subprogram`, ptyio sets the attached tty to raw mode, and copies the original mode to the pty. Before exiting, ptyio restores the original mode of the attached tty.

  Whenever `subprogram` writes a byte to the job control pipe, ptyio stops itself, using the stop signal given by that byte. It restores the mode of the attached tty before stopping. After ptyio continues, it sets the attached tty to raw mode again, and then sends SIGCONT to `subprogram`

  ptyio passes window-size changes through to the pty.

  Many programs handle tty modes incorrectly when they are run in the background; for example, try

      (sleep 2;vi) &; vi

  ptyio handles this situation correctly.

-T

  (Default.) Not attached to a tty.

  Before running `subprogram`, ptyio sets the pty mode to sane mode. Whenever `subprogram` writes a byte to the job control pipe, ptyio sends SIGCONT to `subprogram`.

-r

  (Obsolete.) Remote mode.

  Before running `subprogram`, ptyio sets the pty mode to raw mode, and enables TIOCREMOTE on the master. After reaching end of file on standard input, ptyio writes 0-byte packets to the pty master, which (with correct TIOCREMOTE implementations) produces end-of-file for any program reading the pty slave.

## Raw mode

Raw mode eliminates input echoing, input line buffering, input line editing, input signals (control-C producing SIGINT, control-Z producing SIGTSTP, etc.), output conversion of LF to CR LF, and XON/XOFF flow control. It is, unfortunately, not completely clean: if too much tty input arrives at once, the kernel will discard characters.

## Sane mode

Sane mode supports input echoing, input line buffering, input signals, input conversion of CR to LF, 8-bit input, output conversion of LF to CR LF, and XON/XOFF flow control. It supports the following keys: delete for ERASE, control-backslash for QUIT, control-C for INTR, control-D for EOF, control-O for DISCARD, control-R for REPRINT, control-T for STATUS, control-U for KILL, control-V for LNEXT, control-W for WERASE, control-Y for DSUSP, and control-Z for SUSP.

## History

ptyio was originally part of Daniel J. Bernstein's ptyget toolset in 1996.

## Author

Original code and documentation by Daniel J. Bernstein. Documentation modernizations by Jonathan de Boyne Pollard.