Try the expect/autoexpect Linux commands. Arcane, but extremely useful.
I'm still working out how to use expect myself, but here's an example of an interactive bash script that I got to work with expect (expect apparently works with any interactive command-line program/script, so this could also be done with a Fortran program).
This is the bash script, named "my_interactive_script.sh":
#!/bin/bash
lat_lon_str=$1
echo lat_lon_str is $lat_lon_str
echo "Howdy"
echo " Hello, who is this?"
read name
echo "here is another question"
echo "What's your favorite color?"
read colour
echo "How many cats do you have?"
read n
echo "${name}'s favourite colour is $colour; he has $n cats; he lives at lat/lon $lat_lon_str"
If I call this script with ./my_interactive_script.sh "49.0, -123" and provide the interactive responses when prompted, I get this output:
lat_lon_str is 49.0, -123
Howdy
Hello, who is this?
Bob
here is another question
What's your favorite color?
red
How many cats do you have?
47
Bob's favourite colour is red; he has 47 cats; he lives at lat/lon 49.0, -123
To run this script non-interactively, I create an expect script named "invoke_script.exp":
#!/usr/bin/expect
set lat_lon_str [lindex $argv 0]
spawn ./my_interactive_script.sh $lat_lon_str
expect -re ".*is this.*$"
send -- "Jim\r"
expect -re "ite co.*$"
send -- "cyan\r"
expect -re "you have?"
send -- "zero\r"
expect eof
If I call the expect script with expect invoke_script.exp "49.5, -123.0" , then I get this output:
spawn ./my_interactive_script.sh 49.5, -123.0
lat_lon_str is 49.5, -123.0
Howdy
Hello, who is this?
Jim
here is another question
What's your favorite color?
cyan
How many cats do you have?
zero
Jim's favourite colour is cyan; he has zero cats; he lives at lat/lon 49.5, -123.0
The expect script has answered the interactive questions with the hard-coded stock answers "Jim", "cyan", and "zero", with no need for user interaction.
You'll notice I used the "-re" option with expect to allow the use of regular expressions. I found this to be critical to making expect work with this example. If I didn't use regular expressions, the script would hang. I found that expect was trying to match some weird concatenation of the current prompt string and parts of the previous prompt strings (call expect with the -d option to see verbose output for debugging purposes). I don't understand this, but it may have something to do with the "buffers" the man page talks about. Presumably there's a correct way to clear the buffers as you go, but this regexp solution was an easy workaround.