views:

61

answers:

3

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 there a way I can have a script do all this work ?

+3  A: 

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

Chris Dodd
to add: I found a book called `Exploring Expect`, which is pretty good.
Gollum
A: 

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.

Paul Nathan
can you please provide a simple example in any one of them ? if possible.
Gollum
@Gollum: I would need a specific problem statement with specific inputs and outputs. Can you provide that?
Paul Nathan
sure, if I say _foo.exe_ is asks _enter your file name :_ now I need to enter the file name, then asks me _enter the type of test_ .....I want to put all these answers in one file or some script which does that automatically? But I do not want to waste your time, I am learning expect too. so its okay if you have to spare extra time for this.
Gollum
+1  A: 

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.

Steve Jessop
Steve, the program is interactive, with many combinations. not possible to manually input everything, that too every time we run it.
Gollum