title: How to redirect stdout for a subprocess?
body: <pre><code>def StartProc(dir, parm):
      global proc    
  
      proc_log = open(dir + os.sep + "MyLog.txt","w")  #new path for each file
  
      if parm:
          proc = subprocess.Popen(path, 0, None, subprocess.PIPE, proc_log, None)
      else:
          MyReset(proc)                     #reset the process(proc) to its default values
          proc.stdout = proc_log            #no effect
          print "fptr ", proc.stdout
      #endif
  #enddef
  
  prm = True
  
  for i in range(0, 5):
      StartProc(i, prm)
      prm = False
  #endfor
  </code></pre>
  
  <p>What I want to do is to start an executable only once, but on each iteration I want to redirect the process output to a different file. What is happening, is that files are created in the different path, but output is redirected to the file that is created first time.</p>
  
  <p>Note: <code>MyReset()</code> initializes the process (executable) to its default values after the first iteration.</p>
  
  <p>Will the following line change the process stdout to new file?</p>
  
  <pre><code>proc.stdout = proc_log
  </code></pre>