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
arun


See More: Script to input another program

Report •

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

Report •

#2
November 26, 2010 at 02:32:43

For example, let me call the external program as prog_name.
$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
ABCD
25
sdbfgf
khfds
000000000
(enter key)

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

Hope you understood my point.
thanks


Report •

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

#!/bin/bash

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" ]]
then
   echo_n "Please enter you phone number : "
   read phone
fi
echo "Thank you..... all your data are saved."
# end script

Now, place your input into a data file:

ABCD
25
sdbfgf
jkhfds
y
000000000

and then execute prog_name using redirection:

prog_name < datafile


Report •

Related Solutions

#4
November 26, 2010 at 14:09:23

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

Report •

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

Report •

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

Report •

Ask Question