<?xml version="1.0" encoding="UTF-8"?>
<!-- **************************************************************************
.... For copyright and licensing terms, see the file named COPYING.
.... **************************************************************************
.-->
<?xml-stylesheet href="docbook-xml.css" type="text/css"?>

<refentry id="pty-run">

<refmeta xmlns:xi="http://www.w3.org/2001/XInclude">
<refentrytitle>pty-run</refentrytitle>
<manvolnum>1</manvolnum>
<refmiscinfo class="manual">user commands</refmiscinfo>
<refmiscinfo class="source">nosh</refmiscinfo>
<xi:include href="version.xml" />
</refmeta>

<refnamediv>
<refname>pty-run</refname>
<refpurpose>run a program under a pseudo-terminal </refpurpose>
</refnamediv>

<refsynopsisdiv>
<cmdsynopsis>
<command>pty-run</command>
<arg choice='opt'>-t</arg>
<arg choice='req'><replaceable>next-prog</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>

<refsection><title>Description</title>

<para>
<command>pty-run</command> is a utility that expects file descriptor 4 to be the back end (called "master side" in older documentation) of a pseudo-terminal and the <envar>TTY</envar> environment variable to be the full device filename of the front end.
(<citerefentry><refentrytitle>pty-allocate</refentrytitle><manvolnum>1</manvolnum></citerefentry> can be used to set this process state up.)
</para>

<para>
It spawns <replaceable>next-prog</replaceable>, closing the back-end file descriptor in the child process, and then enters a loop where it simultaneously:
</para>

<itemizedlist>

<listitem>
<para>
writes all data received from the back end to its own standard output, until the back end signals hangup (i.e. when the line discipline would set modem control lines, as it would on a real serial device, to signal hangup because the last front-end file descriptor is closed);
</para>
</listitem>

<listitem>
<para>
writes all data received from its standard input to the back end, until its standard input signals EOF with a 0 byte read; and
</para>
</listitem>

<listitem>
<para>
acts upon state changes in the spawned child process.
</para>
</listitem>

</itemizedlist>

<para>
It has two modes:
</para>

<itemizedlist>

<listitem>
<para>
If the <arg choice='plain'>-t</arg> option was used, it behaves in "pass-through TTY" mode.
</para>

<para>
It copies the terminal mode settings from its standard input or output to the pseudo-terminal and sets both its standard input and output to "raw" mode.
If the child process stops with a stop signal, it undoes this and stops itself.
When it receives a <code>SIGCONT</code>, it re-does it and sends a <code>SIGCONT</code> to its child.
</para>
</listitem>

<listitem>
<para>
In the default if the <arg choice='plain'>-t</arg> option is not used, it behaves in "pipe" mode.
</para>

<para>
It makes no alteration to terminal mode settings.
If the child process stops with a stop signal, it simply sends it a <code>SIGCONT</code> immediately.
</para>
</listitem>

</itemizedlist>

<para>
<replaceable>next-prog</replaceable> may contain its own command line options, which <command>pty-run</command> will ignore.
</para>

</refsection><refsection><title>Security</title>

<para>
<command>pty-run</command> does not touch the front-end device at all.
The front-end device race condition that must be avoided for <citerefentry><refentrytitle>open-controlling-terminal</refentrytitle><manvolnum>1</manvolnum></citerefentry> (q.v.) and similar front-end programs should have already been handled by whatever created the pseudo-terminal (e.g. <citerefentry><refentrytitle>pty-allocate</refentrytitle><manvolnum>1</manvolnum></citerefentry>).
</para>

</refsection>
<refsection><title>See also</title>

<variablelist>
<varlistentry>
<term>
<citerefentry><refentrytitle>console-terminal-emulator</refentrytitle><manvolnum>1</manvolnum></citerefentry>
</term>
<listitem>
<para>an I/O pump that pumps data in both directions between the back end of a pseudo-terminal and an abstraction of a virtual terminal's display and human input device hardwares</para>
</listitem>
</varlistentry>
</variablelist>

</refsection>

<refsection><title>Author</title>
<para><author><personname><firstname>Jonathan</firstname> <surname>de Boyne Pollard</surname></personname></author></para>
</refsection>

</refentry>
