title: Running shell commands from Python and printing the output in real time
body: <p>I want to write a function that will execute multiple shell commands one at a time and print what the shell returns in real time.</p>
  
  <p>I currently have the following code which does not print the shell (I am using Windows 10 and python 3.6.2):</p>
  
  <pre><code>commands = ["foo", "foofoo"]
  p = subprocess.Popen("cmd.exe", shell=True, stdin=subprocess.PIPE, \
                       stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  for command in commands:
      p.stdin.write((command + "\n").encode("utf-8"))
  p.stdin.close()
  p.stdout.read()
  </code></pre>
  
  <p>How can I see what the shell returns in real time ?</p>
  
  <p>Edit : This question is not a duplicate of the two first links in the comments, they do not help printing <strong>in real time</strong>.</p>