Simulate input to another program

3

31337one

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
 
T

TeCh

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top