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

Unable to fake terminal input with termios.TIOCSTI

$
0
0

Most of the code samples I've seen are trying to read from stdin without local echo. To do this they modify the "local modes" flag to remove the setting to "Echo input characters". I thought I could just modify the "input modes" flag to TIOCSTI which is for "Insert the given byte in the input queue.". However, even though I run the script as root, it has no effect. anything I write to the fd seems to go to the terminal output, rather than the terminal input. Basically what I want to do is this exact thing, but in pure python.

"""termfake.pyUsage: sudo python termfake.py /dev/ttys002Get the tty device path of a different local termimal by running `tty`in that terminal."""import sysimport termiosfd = open(sys.argv[1], 'w')fdno = fd.fileno()# Returns [iflag, oflag, cflag, lflag, ispeed, ospeed, cc]tatters = termios.tcgetattr(fdno)print('original', tatters)tatters[0] = termios.TIOCSTIprint('TIOCSTI', termios.TIOCSTI)# Set iflagtermios.tcsetattr(fdno, termios.TCSANOW, tatters)# Verify setting changewith open('/dev/ttys002', 'w') as fd2:    print('modified', termios.tcgetattr(fd2.fileno()))fd.write('This is test\n')fd.close()

Viewing all articles
Browse latest Browse all 3

Trending Articles