Pseudoterminal master reads what it has just written

前端 未结 2 537
轻奢々
轻奢々 2021-02-06 02:22

I\'m working on a project that interfaces \"virtual devices\" (python processes) that use serial port connections with real devices that also use serial ports, and I\'m using ps

2条回答
  •  梦毁少年i
    2021-02-06 03:04

    I'm pretty sure this is because echoing is on by default. To borrow from the Python termios docs, you could do:

    master, slave = os.openpty()    # It's preferred to use os.openpty()
    old_settings = termios.tcgetattr(master)
    new_settings = termios.tcgetattr(master)   # Does this to avoid modifying a reference that also modifies old_settings
    new_settings[3] = new_settings[3] & ~termios.ECHO
    termios.tcsetattr(master, termios.TCSADRAIN, new_settings)
    

    You can use the following to restore the old settings:

    termios.tcsetattr(master, termios.TCSADRAIN, old_settings)
    

提交回复
热议问题