Catching subprocess stdout stream

Thomas Jansson tjansson60 at
Mon Sep 8 17:37:28 CEST 2008

Dear all

I have tkinkter based frontend to a Fortran based program. I use
subprocess to launch the fortran program as a child process and I wish
to see the output of the fortran program as it is created in the

The fortran program can take up to 20 minuttes to finish and at the
moment the I will first see any output after the fortran program is
done. How make my function write the output of the process as it

def runprogram(Icommand, Ijobfile, Ioutput):
    if == "posix":
        os.system(pythonpath+"/bin/"+Icommand+"< "+Ijobfile+" | tee
    elif == "nt":
        import subprocess
        ofile = open(Ioutput, 'w')
        p = subprocess.Popen([os.path.join(pythonpath, "bin", Icommand
+ '.exe')],

	while p.poll() is None: #Check if child process has terminated.
            o = p.stdout.readline()
            print o,

Kind regards
Thomas Jansson

More information about the Python-list mailing list