title: difference between popen and exec python
body: <p>Can anyone explain what is the difference between Popen and exec in Python</p>
  
  <p>Im able to accomplish the same task to execute a program dynamically using exec and Popen.</p>
  
  <p>The code here uses the EXEC approach but what will happen if I use the Popen approach.</p>
  
  <p>code1.py</p>
  
  <pre><code>def runjob(src, job):
      x = "from {src} import *" +  '\n' + "{job}(parm1=)"
      y = x.format(src=src, job=job)
      exec ( 'from ' + src + ' import *' + '\n' + job  + '(10)' )
  
  
  def main():
      runjob(c:/python27/test_job', 'il')
  </code></pre>
  
  <p>code2.py</p>
  
  <pre><code>def fl(parm=None):
      print 'function1'
      print parm
  
  def f2(parm=None):
      print 'function 2'
      print parm
  
  def f3(parm=None):
      print 'function 3'
      print parm
  </code></pre>