1

I am facing with an automation problem in Python. I am pretty new in using the subprocess module that I intend to use for this task. I am working with Python 3.8 and Windows 10. I have a .exe program that I want to run inside a python script. With the following commands:

import sys, string, os, subprocess
from subprocess import PIPE, Popen, STDOUT, STARTUPINFO
s = Popen("my_fortran_code.exe", stdin=PIPE, stdout=PIPE, stderr=PIPE, shell = True)

I successfully start the executable Fortran code but, after that, the code needs some user inputs from the keyboard interactively. I tried to pass the inputs using communicate as follows:

out = s.communicate(input=b'1\n0\n1\nfile_name\n')[0] 

but the Fortran code doesn't receive the inputs. Some suggestions about this problem? Thanks a lot!

jack
  • 1,658
  • 1
  • 7
  • 18
  • What does the Fortran program look like? What ports are you using for input? – cup Feb 13 '21 at 00:26
  • Also have a look at https://stackoverflow.com/questions/16768290/understanding-popen-communicate/16770371#16770371 – cup Feb 13 '21 at 03:19
  • My Fortran code uses msflib to open a gui. So, the user have to give the inputs interactively without using the command window. I expected that this task would be possibile by communicate but it doesn't work... what do you mean with ports? – Lorenzo Russo Feb 15 '21 at 08:35
  • Do you use write(*,fmt) or write(6,fmt). 6 would be the port. What numbers are you using? If running standalone, do they write to the screen? – cup Feb 15 '21 at 08:47
  • The Fortran code uses write(*,*) and it writes to the screen if I run it standalone. – Lorenzo Russo Feb 16 '21 at 09:25

0 Answers0