python - subprocess.Popen and buffered process output -


from inside python code, want run binary program gets parameters stdin. using subprocess module, should 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   # stdout 

now, launches program, python script hangs there. understand may due gfortran (which use compile my_program buffering stdout stream. gfortran allows 1 use gfortran_unbuffered_all environmental variable, have done, using flush() intrinsic in fortran code, still no luck: python code still hangs.

you should have better luck using popen.communicate() send strings process' stdin rather manually writing it.

stdoutdata, stderrdata = p.communicate(stdin_stuff) 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -