Script to input another program

November 24, 2010 at 21:43:03
Specs: Linux, intel
Hi, I use one command line program where I am supposed to enter many inputs one after the other (include alphabets, numbers and characters like * and enter key). In this case I would like to know the possibility of using a script which can do this work for me. If I give all required inputs in a file and let the script use these data one by one as required.

I hope some of you can work it out and surprise me!

with thanks and regards

See More: Script to input another program

Report •

November 25, 2010 at 07:52:13
Your question is too vague. Please be more specific

Report •

November 26, 2010 at 02:32:43

For example, let me call the external program as prog_name.
Welcome to the program prog_name.
Feed you name: ABCD
Hello ABCD, please feed some additional inputs.
Your age ? 25
Place of birth : sdbfgf
Country living in:jkhfds
Thanks for the information you provided.
Would you like to disclose your phone number(y or enter key for yes):
Please enter you phone number :000000000
Thank you..... all your data are saved.

Suppose the external program works like that.
Then let me make an input file with following contents
(enter key)

Now I need a script to feed these inputs to the program as it asks.

Hope you understood my point.

Report •

November 26, 2010 at 13:58:33
Ok, suppose your bash script prog_name looks something like this:


echo "Welcome to the program $0"
echo "Feed your name: "
read name

echo "Hello ${name}, please feed some additional inputs."
echo "Your age ? "
read myage
echo "age is $myage"

echo "Place of birth : "
read mybirthplace
echo "my birthplace is: $mybirthplace"

echo "Country living in: "
read mycountry
echo "my country is: $mycountry"

echo "Thanks for the information you provided."
echo "Would you like to disclose your phone number(y or enter key for yes): "
read question

if [[ $question == "y" ]]
   echo_n "Please enter you phone number : "
   read phone
echo "Thank you..... all your data are saved."
# end script

Now, place your input into a data file:


and then execute prog_name using redirection:

prog_name < datafile

Report •

Related Solutions

November 26, 2010 at 14:09:23

Thanks a lot...It works!!!!!!!!!!!

Report •

May 20, 2011 at 00:58:07
I was looking for something like this worked for me too
Thanks a log!!!

Report •

May 20, 2011 at 00:58:52
I was facing the same problem
thanks a lot, Worked for me too!!!

Report •

Ask Question