I am attempting to run a number of student FORTRAN programs from a python script. These programs are not written in any particular order and often rely on the simple FORTRAN read(*,*) command. A simple program could be:
program main
implicit none
real :: p,t
write(*,*)'Enter p'
read(*,*)p
write(*,*)'Enter t'
read(*,*)t
write(*,*)p,t
end program main
This code pauses and allows the user to enter in certain information based on the prompt. I would like similar feature by using the subprocess Popen command. The script will not know what the inputs are before running, or if they even need to happen.
Currently, for programs with no necessary input the following script works:
p = sub.Popen('./file',stdout=sub.PIPE,stderr=sub.PIPE,stdin=sub.PIPE,shell=True)
output,error = p.communicate()
Is there any way to allow the script runner to enter the data in the terminal as the program is being run?
It looks like you want to use
pexpect:To pass interactive control of the program to the user, use
child.interact().