Quantcast
Channel: Unable to fake terminal input with termios.TIOCSTI - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Ulfalizer for Unable to fake terminal input with termios.TIOCSTI

$
0
0

TIOCSTI is an ioctl (documented in tty_ioctl(4)), not a terminal setting, so you can't use tcsetattr() -- you need to feed each character of the fake input to ioctl() instead. Never had to do ioctl's from Python before, but the following seems to work for running an ls in a different terminal (specified as the argument, e.g. /dev/pts/13) that's running Bash:

import fcntlimport sysimport termioswith open(sys.argv[1], 'w') as fd:    for c in "ls\n":        fcntl.ioctl(fd, termios.TIOCSTI, c)

TIOCSTI requires root privileges (or CAP_SYS_ADMIN to be more specific, but that's usually the same in practice) by the way -- see capabilities(7).


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>