Shell script to pass multiple stdin to prorgam?

Running on AIX 5.3L.

I have a program "foo" written in Fortran that requires 3 levels of inputs from stdin (command prompt).

> foo
Enter Input 1: a
Enter Input 2: b
Enter Input 3: c
running foo
success!
>

How do I get a shell script to run this automatically?

> echo "a" | foo
Enter Input 1: a
The READ statement on the file (standard input) cannot be completed because the end of the file was reached. The program will stop.
>

> echo "a b c" | foo
Enter Input 1: a b c
The READ statement on the file (standard input) cannot be completed because the end of the file was reached. The program will stop.
>

> echo "a\nb\nc" | foo
Enter Input 1: a
The READ statement on the file (standard input) cannot be completed because the end of the file was reached. The program will stop.
>

I have tried almost everything: \r, \n, using printf ... etc.

How do I pass multiple levels of input through std input?

Have you tried using 'here' doc? Something like:


foo <<EOF
a
b
c
EOF

#!/bin/ksh
> answer.txt
for val in 1 2 3
do
      echo "Value$val:\c"
      read value
      echo "$value\r" >> answer.txt  # need cr+lf
      #echo "$value" >> answer.txt    # only lf
done
someprog < answer.txt