Simulate input to another program

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • 31337one@gmail.com

    #1

    Simulate input to another program

    Hello everyone,

    I am using a python script as a way to test another program that I have
    written in C++. The program cannot be altered. It needs to stay the way
    it is.

    I need to simulate a few keystrokes to the application while it is
    running. The application uses number keys and y and n to navigate a
    basic menu.

    Is there a way within python to simulate the keystrokes to this other
    program.

    Both the application and the python script are running in a terminal.

    Thanks for all your help,

    -E

  • TeCh

    #2
    Re: Simulate input to another program

    31337one@gmail. com wrote:
    I am using a python script as a way to test another program that I have
    written in C++. The program cannot be altered. It needs to stay the way
    it is.
    >
    I need to simulate a few keystrokes to the application while it is
    running. The application uses number keys and y and n to navigate a
    basic menu.
    >
    Is there a way within python to simulate the keystrokes to this other
    program.
    I think this is possible with an expect module, such as
    http://pexpect.sourceforge.net/.

    <quote>
    Description: Python module for automating interactive applications
    Pexpect is a pure Python module for spawning child applications;
    controlling them; and responding to expected patterns in their
    output. Pexpect works like Don Libes' Expect. Pexpect allows your
    script to spawn a child application and control it as if a human were
    typing commands.
    </quote>

    --
    TeCh

    Comment

    • 31337one@gmail.com

      #3
      Re: Simulate input to another program

      So there is no easy built in way to do this?

      Comment

      • Antoon Pardon

        #4
        Re: Simulate input to another program

        On 2006-07-27, 31337one@gmail. com <31337one@gmail .comwrote:
        So there is no easy built in way to do this?
        Depends on what you mean by easy. A look at the pty module
        may help.

        --
        Antoon Pardon

        Comment

        Working...