From inside python code, I want to run a binary program that gets its parameters from stdin. Using the subprocess module, this should be straightforward:
import subprocess
command = [ 'my_program' ]
p = subprocess.Popen( command, \
stdin = subprocess.PIPE, stdout = subprocess.PIPE, \
env={ "GFORTRAN_UNBUFFERED_ALL": "1"} )
p.stdin.write ( stdin_stuff )
while True:
o = p.stdout.readline()
if p.poll() != None:
break
# Do something with stdout
Now, this launches the program, but the python script just hangs there. I understand that this may well be due gfortran (which I use to compile my_program is buffering its stdout stream. gfortran allows one to use the GFORTRAN_UNBUFFERED_ALL environmental variable, as I have done, as well as using the FLUSH() intrinsic in the fortran code, but still no luck: the python code still hangs.