title: C subprocess from Python: sub.stdin.write IOError Broken Pipe
body: <p>I am getting a Broken Pipe error when writing a large quantity of data very fast to a C subprocess.</p>
  
  <p>So I am running a c subprocess from a python script:</p>
  
  <pre><code>process = subprocess.Popen("./gpiopwm", stdin=subprocess.PIPE)
  while True:
      process.stdin.write("m2000\n")
      print "bytes written"
  </code></pre>
  
  <p>Sectio of main loop of gpiopwm.c:</p>
  
  <pre><code>printf("1\n");
  while (1) {
      fgets(input,7,stdin);  // Takes input from python script
      printf("2\n");
  
      numbers = input+1;      // stores all but first char of input 
      char first = input[0];  // stores first char of input
  
      if (first=='m') {
          printf("3\n");
          printf("%s\n",numbers);
      }
  }
  </code></pre>
  
  <p>However, the output from this is as follows:</p>
  
  <pre><code>1
  bytes written
  Traceback (most recent call last):
       File "serial-receive-to-pwm.py", line 20, in &lt;module&gt;
       process.stdin.write("m2000\n")
  IOError: [Errno 32] Broken pipe
  </code></pre>
  
  <p>The C program evidently breaks at the <code>fgets</code> line, as <code>2</code> is never printed.
  What have I done wrong? How can I avoid this?</p>
  
  <p>EDIT:
  I've updated the <code>fgets</code> line so that it does not include the dereference argument, but am still getting the broken pipe error.</p>
  
  <p>EDIT:
  <code>input</code> is initialized as <code>char *input="m2000";</code></p>