问题
I'm in a course for C++ programming.
Our professor created a linux validation script against which our program output must match exactly.
It's running out of his own program and generates an output.txt file, then compares it against his output file, if it doesn't match it rejects the script.
The problem is, this program excepts probably 150-200 lines of input and if anything goes in wrong you have to start all over again. If you even enter an incorrect char, it must be restarted as the backspace registers as a character of its own.
How might I generate a bash script that would feed all of the input into the program automatically?
NOTE: We have to use his program as in: ~professor.name/submit asigname
回答1:
How might I generate a bash script that would feed all of the input into the program automatically?
Without any example code or input/output, it is hard to gauge what precisely is that you need.
Otherwise, for a generic tool to automate interactive console programs, I would suggest to take a look at the Expect.
回答2:
You can create a text file:
answers.txt
answer1
answer2
...
answerN
and use that as stdin for the program:
./your_program < answers.txt
来源:https://stackoverflow.com/questions/34055210/script-program-inputs-in-bash-ubuntu-linux