Reputation: 11
I am creating a python script that runs a fortran code multiple times using different input values. I have tried running the fortran code using: os.system('./fortrancode')
. However, the fortran code then asks for new user input. This has to be provided over multiple lines (multiple read statements in the fortran code) in the following format:
[run fortran code]
filename_input.txt [press enter]
filename_output.txt [press enter]
1 [press enter]
1 [press enter]
1 40 [press enter]
-10 [press enter]
At the moment I am unable to provide the fortran code with these input parameters from my python script. (Probably because os.system() is waiting for the terminal to do an output?) I've also tried to do os.system('./fortrancode\nfilename_input.txt\nfilename_output.txt\n1\n1\n1 40\n-180\n')
, but that didn't seem to work either.
What would be the correct way to provide the fortran code with the input parameters I'm looping over in the python script?
Upvotes: 1
Views: 361
Reputation: 731
Solution 1:
import subprocess
result = subprocess.Popen(['./fortrancode', 'filename_input.txt','filename_output.txt','1', '1', '1', '40', '-180'])
Solution 2:
You can call from python using F2PY
Upvotes: 2