Search code examples
pythonswitch-statementtty

Python - How to run python script in a specific tty, in Linux?


In the project, I shall boot to the Linux console mode (init 3), and then run a python script using curses library (with console UI) in a specific tty.

For example, OS boots to tty 0, and I type:

sudo chvt 2 && sudo python /root/aaa.py

This is Ubuntu Live Desktop OS, so sudo would not prompt for password and just execute the command with elevated privilage.

The tty does switch to 2, but /root/aaa.py (with curses library UI) is executed in tty 0...

If I want the script is executed in tty 2 and the UI is shown in tty 2, how to do it?

Many thanks.


Solution

  • I think the openvt command is what you're looking for. Remember that you'll need root privileges to execute it.