0

Not sure if this is related. but I saw when using OSMC. some shell scripts have something like this:

sudo openvt -c 7 -s -f clear

I searched the help and it says it executes the command on new virtual terminal. but I still don't understand why to use this? and why always specifying a number like 7?

This usually is used for example to launch emulationstation from OSMC kodi.

1

There are sort of a few ways to define "virtual terminal", a strict and more formal way and a more casual and perhaps common one (depending where you are...), the latter of which is really a colloquial synonym for terminal emulator or pseudo terminal.

The strict definition refers to the text consoles usually accessible (at least on linux systems) via AltCtrlF[1-6] -- actually F7+ may also work, but generally only the first 6 have a login prompt running on them, so anything beyond that will be a blank black screen (however, programs can still use them for output). If you look in /dev these are tty[N] devices (beware tty___ is used as a prefix for other terminalesque things) and there are probably a lot more than just 6 or 7, or the number of F-keys.

These are called "virtual" because historically a single terminal was a physical piece of hardware combining a screen and keyboard. Virtual terminals probably require the OS to have access to such hardware in order to be useful, but they're not the hardware itself. They're software implementations of hardware protocols derived from very old school equipment (with some new school tweaks). Hence you can have an arbitrary number of them running with just one screen and keyboard.

Pseudo Terminals and Terminal Emulators

A pseudo terminal is a more general case of a virtual terminal. They're used for, e.g., remote logins and terminal emulators. Terminal emulator often refers specifically to the GUI window based programs you are familiar with (e.g., on Raspbian, LXTerminal) but might also be construed to include that and virtual terminals proper.

Anway, openvt is called openvt because it is for opening a command via virtual terminals (VTs) in a strict sense, i.e., not including GUI emulators, remote login terminals, etc. These have some characteristics which place them closer to the actual hardware than most pseudo terminals. For example, the GUI desktop is actually run via a VT, and when a desktop is in use, it will occupy one. If you cycle through alt-ctrl-f[1-7] you should notice this; I used 7 instead of 6 because it is common to use the 7th one for this purpose (since it's usually the first one with no login prompt running), which is what it looks like that command targets:

sudo openvt -c 7 -s -f clear

The -s switch means "Switch to the new VT when starting the command. The VT of the new command will be made the new current VT" (from man openvt). So this might be used before running some other application, e.g., so any output it produces can't be confused with anything else, or, if it is a GUI application which can run on the framebuffer (i.e., without a formal desktop), so there is just a blank screen shown during the time it takes to load and start.

  • Thanks, that's very informative. I understand it now well. how about clear. why they use clear? isn't it just to clear the terminal screen? in the case of a vt. generally speaking no one is going to see it, right? is there another purpose? – Dreaded semicolon Oct 12 '16 at 17:51
  • The -s switch means (from man openvt) "Switch to the new VT when starting the command. The VT of the new command will be made the new current VT". If this is right before launching a GUI application it might be so any clutter that's already there is removed, leaving an empty screen during whatever amount of time it takes the app to load and start. Also, clear clears the "scrollback buffer", so this ensures if the app fails and/or leaves text output behind (which wouldn't be unusual), there won't be any confusion about where it came from. – goldilocks Oct 12 '16 at 17:56
1

The command System.Exec() can be used in custom menu items in Kodi to execute shell commands.

openvt comes in handy when you're trying to execute a shell command or script from Kodi that shuts down Kodi and opens a new application, as Kodi stops executing the command as soon as it shuts down. Opening a new Virtual Terminal and executing the command in it ensures the command will continue running after Kodi stops.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.