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

1

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

If you use diff -u to generate the difference, the output might be more readable.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.