title: python subprocess blocked by while loop
body: <p>i would like to control a C program with a Python script. The C program look like this:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void main(){
      int num;
      do{
          printf("insert a number: \ninsert 3 to exit\n");
          scanf("%d", &amp;num);
          switch(num){
              case 1: {printf("you pressed 1\n");break;}
              case 2: {printf("you pressed 1\n");break;}
              default:{printf("you pressed another key\n");}
          }
      }while(num!=3);
  }
  </code></pre>
  
  <p>and my python script is using subprocess:</p>
  
  <pre><code>   import subprocess
     p=subprocess.Popen('./Cprogram', stdin=subprocess.PIPE, stdout=subprocess.PIPE)
     p.stdin.write('1')
     p.communicate()
  </code></pre>
  
  <p>and the result is that the python shell is blocked with the cursor on a empty line.</p>
  
  <p>without the while in the c program the script works fine. How i could manage it ?</p>
  
  <p>Thank you</p>