假设我有一个简单的C++程序,它接收输入和输出一些字符串。这样的(实际的程序要复杂得多,但仍然基于文本):使用python运行C++程序并进行测试
$ ./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!
我以前没有使用过Python的,但有可能写一个python脚本来运行这个程序,喂它输入和输出结果标准输出?我问了关于使用C++运行它的问题here,但它看起来太复杂了。如果你能指导我看一些代码示例,那将会非常棒。任何帮助,将不胜感激。
你可能还想考虑'expect'(http://en.wikipedia.org/wiki/Expect) – aschepler