Script program inputs in bash ubuntu linux [closed]

强颜欢笑 提交于 2019-12-13 08:59:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!