Reputation: 33
I have an executable of a program, written in Fortran that needs interactive input, for example 20 inputs. What I want, is to give the first 19 inputs through input redirection but the last one from my keyboard. The reason is because when I run the program I get a message
file list_wall.dat written - modify it to group walls
modify wallList.dat (add flag type) - enter 1 when ready
So before I press 1, I need to modify a file manually and then press 1 manually. I have tried to run it like this
./my_interactive_program < input.in
where I have the first 19 lines written in this input.in file. However, when it reaches the last line I get a message like this:
$forrtl: severe (24): end-of-file during read, unit -4, file stdin
So, instead of waiting for my input from the keyboard, it detects the end of the file and the program crashes. Can I do something about it?
Upvotes: 1
Views: 212
Reputation: 72746
A flexible tool to automate interactive programs is expect
. You can use it to feed arbitrary input (say, read from a file and counting the lines) to your fortran program. Once you get to the prompt you issue the command interact
and expect passes control to the terminal's stdin.
Upvotes: 0
Reputation: 247202
If you can ask the user for the 20th input up front:
read -p "input 20: " inp
{ cat input.in; echo "$inp"; } | ./my_interactive_program
Otherwise, expect
is a sledgehammer you can employ:
expect <<'END'
spawn ./my_interactive_program
set fh [open input.in r]
while {[gets $fh line] != -1} {
send -- "$line\r"
}
close $fh
interact
END
Upvotes: 1
Reputation: 5885
What you could do is make a .sh file that outputs all the inputs (are you still with me? :), asks for user input and then outputs that as well:
echo hello
echo world
read input
echo $input
Then run that .sh file and pipe the output through your fortran program.
Upvotes: 0