0

Consider a basic program - SumOf2Numbers.cpp. I can give 2 number as input through command line and it give the sum of the number.

I want to run this program with various inputs like,

./a.out 5 6
./a.out 123456 654321
./a.out -200 200

And the output would be,

5 + 6 = 11
-200 + 200 = 0 
123456+654321 = 777777

I want to automate this process of executing the c++ code and storing the output in a file. I am new to writing scripts. I would like to know how I can do this ? I believe I can do this by writing perl or bash scripts. Can someone guide me to a nice tutorial on this.

PS: I am sure there would be lot of online tutorials. But I am not sure how exactly I should perform the search.

1 Answer 1

4

This can be done easily with a shell script:

#!/bin/sh
(
  ./a.out 5 6
  ./a.out 123456 654321
  ./a.out -200 200
) > output.txt
Sign up to request clarification or add additional context in comments.

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.