[Python] How to have a parent terminal view and pilot a child pseudo-terminal

Discussão em 'Python' iniciado por Stack, Setembro 4, 2025.

  1. Stack

    Stack Membro Participativo

    Goal: In Python have a parent terminal start a program in a child pseudo-terminal (PTY), see its outputs and provide its inputs. At any given time, the parent terminal should be able to query what's on the child's screen at any character index

    So in pseudocode the parent would do:

    child_terminal = pty.openpty()
    child_terminal.exec(my_program)

    child_terminal.charAt(2, 4) # Returns "@"
    child_terminal.submitInput("A")
    child_terminal.charAt(2, 4) # Returns "!" now because the contents of the screen changed per the input submitted


    Is this a workable task or is there something about command line rendering/state that makes it unfeasible? I thought it would be a common use case for scraping/automation but am not seeing much for this

    Continue reading...

Compartilhe esta Página