You can try writing an Expect script.
> Date: Fri, 16 Nov 2001 08:18:38 -0500
> Newsgroups: comp.unix.shell
> Subject: Re: How to command a program after it is started from the script?
> > >>>I need to enter keyboard commands to a program that is started with the
> > >>>script. Like press the enter key, or give a number and press enter. I can
> > >>>do it with the keyboard when the program ask me, but the shell script
> > >>>should do if for me. I have to start 100 time the same program and give it
> > >>>always the same command after it is started.
> > >>>How can I do it with a script???
> > >> command <<EOF
> > >> input1
> > >> input2
> > >> input3
> > >> ...
> > >> EOF
> > >> Where input# are the lines that you want to feed as input to the command.
> > >Is it possible to introduce a "sleep 1" in between? Or any timing before
> > >the next command?
> > while read line
> > do
> > echo "$line"
> > sleep 1
> > done <<EOF | command
> > input1
> > input2
> > input3
> > EOF
> > If you want to get any more complex than this, you'll probably want to do
> > it as an Expect script rather than a shell script.
> Or you could use co-processes in ksh.