开发者

supplying inputs to stdin programatically line by line?

I have a test program which prompts for input from user(stdin), and depending on inputs, it asks for other inputs, which also need to be entered.

is the开发者_如何学Gore a way I can have a script do all this work ?


There's a program called expect that does pretty much exactly what you want -- you can script inputs and expected outputs and responses based on those outputs, as simple or complex as you need. See also the wikipedia entry for expect


I may have misunderstood, but do you have a program which reads the input and does something with it, and you just want to know how to automate providing it some test input?

For a given test case, does the input you provide have to depend on the output from the program, or is it the same every time?

If the input for a given test is the same every time, then just put it in a text file and redirect stdin for your program to read from that file:

myprogram.exe < input.txt

If the input is different each time, for the same test, then this doesn't help. But for a typical simple test, you just want to answer "y" to the first question, "n" to the second, and "hello world" to the third, or whatever.


In the general case, yes, there is.

For more specific tasks, you can get other tools to do the job that will be more specialized and usable for that particular task.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜