title: subprocess.communicate() sending garbage to process?
body: <p>I'm having problems reading/writing to stdin/stdout in a child process with subprocess.communicate().</p>
  
  <p>This is the child process (in C)</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main ()
  {
      char buf[128];
      printf("test\n");
      gets(buf);
      printf("%s", buf);
      return 0;
  }
  </code></pre>
  
  <p>This is the program in python that calls that child program</p>
  
  <pre><code>import subprocess
  
  proc = subprocess.Popen('./test', stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  
  stdin, stderr = proc.communicate()
  print stdin
  proc.communicate(stdin)
  stdin, stderr = proc.communicate()
  print stdin
  
  print stdin
  </code></pre>
  
  <p>I would expect this to print</p>
  
  <pre><code>test
  input was test:
  </code></pre>
  
  <p>However, it seems that proc.communicate() causes an EOF for gets(), causing the child application to terminate. Is there anyway I can communicate with the child application without sending an EOF? IE I would like to read to the application AND THEN write to it.</p>