0

Alternative to "openvt"...but for pseudo terminal(pts)... Exists?

Openvrt operate only tty...but not pts.

(Example: lauch comand in specific pts and with user of shell pts destination)

Command <dev pts> <launch_command>
  • 1
    script. script /dev/null. I don't know of any readily available tool which creates a pty without starting a command in it. Please be more clear about what exactly you want to achieve. –  Jan 11 '20 at 16:33

1 Answers1

3

ptyrun and ptybandage

There are plenty of readily available tools that do the equivalent of what openvt does: open a fresh pseudo-terminal and run a designated command with its standard I/O attached to that pseudo-terminal.

  • Daniel J. Bernstein's original ptyrun and ptybandage
  • My ptyrun and ptybandage build on nosh toolset utilities
  • The zpty extension module in the Z shell
% tty ; ptybandage tty
/dev/pts/5
/dev/pts/6
%

Of course, the difference is that in the case of pseudo-terminals, one has to have some process attached to the master side of the pseudo-terminal to actually do something with the I/O. In the case of Bernstein's tools thats the ptyio program. ptyrun and ptybandage are in fact scripts that devolve into the ptyget, ptyio, and ptyspawn programs. The case is similar for my tools, where the pty-run program is the inner I/O workhorse, combined with pty-get-tty and open-controlling-tty.

Which means that if one wants more fine-grained operation, just opening the pseudo-terminal master side and then chain loading something to do the rest, one can invoke pty-get-tty or ptyget directly.

terminal multiplexors

In the case of the terminal multiplexors tmux and screen, there are of course mechanisms (that are parts of those programs) for starting a new (inner) terminal and running a command attached to it. See those programs' doco for details.

existing pseudo-terminals

What these tools (ptyrun, ptybandage, et al.) do not do is run commands attaching them to existing pseudo-terminals. They always create fresh ones.

There's little call for running commands attached to existing pseudo-terminals. But it can be done. It can be done with my toolset, for example. Just set the TTY environment variable to the slave side device filename of the existing pseudo-terminal, and invoke the command via the open-controlling-tty tool.

TTY=/dev/pts/5 open-controlling-tty $SHELL

This creates contention for the terminal amongst different unrelated concurrent processes, of course, and makes one painfully aware of how much job control shells are doing for one. ☺

Also note that several SSH servers and terminal emulators will close the master side if their slave-side child process exits.

what all these are not

Finally, note that these are not input-stuffing mechanisms, for driving an existing interactive shell on an existing pseudo-terminal, sending commands to its input. They all attach new processes to (fresh) pseudo-terminals.

But then that is not what openvt does, either.

Further reading

JdeBP
  • 68,745