title: Multiple inputs in a Python Subprocess PIPE (with stdin or communicate)
body: <p>I've been looking for an answer to the question above.</p>
  
  <p>The Popen command should not return anything, its simply asking for "do you want to continue?" (yes) and the "admin password" taken from a local database.</p>
  
  <p>Current code state is: Everything works fine but asks me the second input, first input passes through.</p>
  
  <ul>
  <li>I'm using an Ubuntu Server (with Python -u)</li>
  <li>Tried flushing after each stdin.write</li>
  <li>Tried communicate (Having problem with it, code loops unlimited times)</li>
  <li>Tried pexpect but also having problems with it too, Popen is more suitable under my conditions I guess.</li>
  </ul>
  
  <p>So, I'm open to suggestions and willing to try your helps. Any help would be appreciated.</p>
  
  <pre><code>        #Input 1
          p = Popen(["foo", "bar"], stdin=PIPE, universal_newlines=True)
          try:
              p.stdin.write('yes' + linesep)
          except IOError as e:
              if e.errno == errno.EPIPE or e.errno == errno.EINVAL:
                  break
              else:
                  raise
          p.stdin.flush()
          #Input 2
          try:
              p.stdin.write(KeyPass + linesep)
          except IOError as e:
              if e.errno == errno.EPIPE or e.errno == errno.EINVAL:
                  break
              else:
                  raise
          p.stdin.flush()
          p.stdin.close()
          p.wait()
  </code></pre>