I have an interactive FORTRAN program that requires various user input. Now I want to save the output of this Fortran program to a variable and use this value in a shell script. I tried
var=`./test` and var=$(./test)
but in both cases, it does not ask the user for input and remains in standby mode. What should I do? An example fortran code is as follows
test.f
program test
character*1 resp1, resp3
integer resp2, ans
write(*,*) 'Think of a prime number less than 10'
write(*,*) 'Say whether it is odd or even'
write(*,*) 'Write o/e'
read(*,*) resp1
if ( resp1 .EQ. 'e' ) then
ans=2
else
write(*,*) 'Is the number close to 4 or 8'
read (*,*) resp2
if ( resp2 == 8 ) then
ans=7
else
write(*,*) 'Is the number greater than or less than 4'
write(*,*) 'Write g or l'
read (*,*) resp3
if ( resp3 .EQ. 'l' ) then
ans=3
else
ans=5
end if
end if
end if
write(*,*) ans
end
Compiled as gfortran test.f -o test
Then I used a script like this
test.sh
var=`./test`
echo "The answer you are looking for is " $var
I believe that there is something very trivial that I can not find. Please help me.
PS This is just an example of code and script, and my actual script and code are very different.
source
share