tags:

views:

45

answers:

2

I've just completed the coding section of simple homework assignment for my C++ class. The second part of the assignment requires us to verify our code's input validation. (The program takes several different values as inputs from a user and prints those values to a file)

I was hoping that I could use bash script for this. Is there any way to use bash script to run and interact with a program? How can I put the program's output into a variable (note that program has a series of input requests and outputs).

Thanks

+3  A: 

To build on @Travis' answer, create two files: one holds your inputs (input.txt) and one holds the expected output (expected_output.txt). Then do the following:

./myprogram <input.txt >output.txt
diff output.txt expected_output.txt

If the diff command has any output, there's a problem.

Matt McClellan
That's a great idea!
Travis Gockel
If you use `diff -u` to generate the difference, the output might be more readable.
ndim
A: 

You can do much of this with a shell script but you might want to consider using some other testing tools instead like CppUnit or expect.

D.Shawley