Python TTY Control Python TTY Control unix unix

Python TTY Control


I can see at least two things you're missing - there may be more:

Firstly, you need to call setsid() in the child process after closing the old standard input/standard output, and before opening the new TTY. This does two important things - it makes your new process the leader of a new session, and it disassociates it from its previous controlling terminal (merely closing that terminal is not sufficient). This will mean that when you open the new tty, it will become the controlling terminal, which is what you want.

Secondly, you need to set the TERM environment variable to match the new tty.


You should have a look at the source of the *tty* programs, to see what they do.

My guess is that they mostly issue a bunch of ioctl commands to initialise the terminal into the mode that programs normally expect (e.g. for login etc). However some of them may also prompt for a username (not password; login does that).