Is there any way to open a program on a specific tty?

14,880

Solution 1

it seems like the following SO-question may answer yours: https://stackoverflow.com/questions/8994593/how-to-reroute-stdout-stderr-back-to-dev-tty

exec >/dev/tty 2>&1 should do it

for only some commands > /dev/tty1 after the command (as stated by David Schwartz) would also work

Solution 2

You could use Linux virtual consoles for this. Each virtual console is a separate text-mode or graphical display, keyboard, and mouse, all sharing the computer's actual display hardware.

Each virtual console can be accessed through the tty devices /dev/ttyN, where N is 1, 2, etc. /dev/tty1 is virtual console 1. If you had a keyboard attached to the computer, you'd press Alt-F1 to get to console 1, Alt-F2 for console 2, and so on (or Ctrl-Alt-FN if the currently-displayed console is running X). There is also a set of programs to work with virtual consoles which you'll have to use, since you don't have a keyboard.

In short:

some-program > /dev/tty1 2>&1

will redirect a program's output to virtual console 1. If console 1 isn't on the monitor, you can switch to it:

chvt 1

A better method is to run openvt to start a command on a virtual console:

openvt -s some-command

This will pick a new virtual console, make it visible on the screen, and run the specified command. Openvt has other options, so check the documentation.

Other useful commands are fgconsole to display the number of the currently-displayed console, and deallocvt to cleanup unused consoles.

All of these commands may require superuser privileges to run.

Share:
14,880

Related videos on Youtube

Mids
Author by

Mids

Updated on September 18, 2022

Comments

  • Mids
    Mids over 1 year

    I have a PC with no mouse or keyboard, but it is connected to a monitor. I was wondering if is it possible to open a program remotely (like via SSH) in a specific tty (like tty1) so I would able to watch the output on the monitor.

    • David Schwartz
      David Schwartz over 9 years
      What's wrong with just redirecting the output to the desired tty? Like ls > /dev/tty1?