title: Repeatedly interacting with program using subprocess
body: <p>I'm trying to run a program that requires successive interactions (I have to answer with strings: '0' or '1') from within my python script.</p>
  
  <p>My code:</p>
  
  <pre><code>from subprocess import Popen, PIPE
  
  command = ['program', '-arg1', 'path/file_to_arg1']
  
  p = Popen(command, stdin=PIPE, stdout=PIPE)
  p.communicate('0'.encode())
  </code></pre>
  
  <p>The last two lines work for the first interaction, but after that the program prints all the following questions on the screen without waiting for their respective inputs. I basically need to answer the first question, wait until the program deals with it and prints the second question, then answer the second question, and so on.</p>
  
  <p>Any ideas?
  Thanks!</p>
  
  <p>PS: I'm using Python 3.3.4</p>