title: Understanding Popen.communicate
body: <p>I have a script named <code>1st.py</code> which creates a REPL (read-eval-print-loop):</p>
  
  <pre><code>print "Something to print"
  while True:
      r = raw_input()
      if r == 'n':
          print "exiting"
          break
      else:
          print "continuing"
  </code></pre>
  
  <p>I then launched <code>1st.py</code> with the following code:</p>
  
  <pre><code>p = subprocess.Popen(["python","1st.py"], stdin=PIPE, stdout=PIPE)
  </code></pre>
  
  <p>And then tried this:</p>
  
  <pre><code>print p.communicate()[0]
  </code></pre>
  
  <p>It failed, providing this traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "1st.py", line 3, in &lt;module&gt;
      r = raw_input()
  EOFError: EOF when reading a line
  </code></pre>
  
  <p>Can you explain what is happening here please? When I use <code>p.stdout.read()</code>, it hangs forever.</p>