title: Executing multiple commands using Popen.stdin
body: <p>I'd like to execute multiple commands in a standalone application launched from a python script, using pipes. The only way I could reliably pass the commands to the stdin of the program was using Popen.communicate but it closes the program after the command gets executed. If I use Popen.stdin.write than the command executes only 1 time out of 5 or so, it does not work reliable. What am I doing wrong?</p>
  
  <p>To elaborate a bit :</p>
  
  <p>I have an application that listens to stdin for commands and executes them line by line.
  I'd like to be able to run the application and pass various commands to it, based on the users interaction with a GUI.
  This is a simple test example:</p>
  
  <pre><code>import os, string
  from subprocess import Popen, PIPE
  
  command = "anApplication" 
  process = Popen(command, shell=False, stderr=None, stdin=PIPE)
  
  process.stdin.write("doSomething1\n")
  process.stdin.flush()
  process.stdin.write("doSomething2\n")
  process.stdin.flush()
  </code></pre>
  
  <p>I'd expect to see the result of both commands but I don't get any response. (If I execute one of the Popen.write lines multiple times it occasionally works.)</p>
  
  <p>And if I execute:</p>
  
  <pre><code>process.communicate("doSomething1")
  </code></pre>
  
  <p>it works perfectly but the application terminates.</p>