PDA

View Full Version : Is it possible to automatically give answers to an interactive program in bash?


gramarga
July 14th, 2007, 01:19 PM
Hello, everyone.

I am using an interactive program that mostly asks questions expecting yes/no answers. I need to run this program 1000 times and would like to do that with bash.

Is there any way to automatically give these yes/no answers to the program, since they will always be the same?

Thanks in advance,
Gabriel.

Ramses de Norre
July 14th, 2007, 02:17 PM
How are they asked, what kind of interface? Can you modify the source of the program asking the questions?
You'll need to give more details...

kknd
July 14th, 2007, 03:44 PM
You can do, redirecting the input / output to the program.
In Java, you can do that with the "Process" class.

slavik
July 14th, 2007, 04:04 PM
program < inputfile_with_predetermined_answers

gramarga
July 14th, 2007, 05:35 PM
Thank you all for the replies.

slavik, your hint was enough to do the job.
Thanks a lot!

Gabriel.

cwaldbieser
July 15th, 2007, 08:58 PM
Thank you all for the replies.

slavik, your hint was enough to do the job.
Thanks a lot!

Gabriel.

If you just want to give the same answer to all the questions, the "yes" command might also work:

$ yes | your-prog

slavik
July 16th, 2007, 09:20 AM
If you just want to give the same answer to all the questions, the "yes" command might also work:

$ yes | your-prog

I did not know that existed :D

Keith Hedger
July 16th, 2007, 09:28 AM
Try using a HERE script,
For full details see the Advanced Bash Scripting guide, its in the repos under abs somthing!