Using python to run a C ++ program and test

Suppose I have a simple C ++ program that takes input and prints some string. Like this (the actual program is much more complicated, but still based on the text):

$ ./game
$ what kind of game? type r for regular, s for special.
$ r
$ choose a number from 1 - 10
$ 1
$ no try again
$ 2
$ no try again
$ 5
$ yes you WIN!

I have not used Python before, but is it possible to write a python script to run this program, submit it to the input and output the results to standard output? I asked a question here about running it using C ++, but it seems too complicated. It would be great if you could direct me to some code examples. Any help would be appreciated.

+5
source share
3 answers

pexpect.

stdin/stdout , -, TTY ( isatty), , , ; . , . pexpect -tty, , , . , , xterm rxvt.

+3

Cram, Python .

+1

, , Python expect. expect "" . Python expect.py, .

. http://code.google.com/p/pycopia/

.

pexpect, , .

0

All Articles