title: Python - Subprocess with STDIN and STDOUT
body: <p>I would like to pass a byte-object from file A.py to B.py where it is incremented by 1 and then passed back. Currently I have the following code and whenever I run <code>python A.py</code>, the program does not print anything. I feel like the problem is in file B.py though I am not sure.</p>
  <p><strong>A.py</strong></p>
  <pre><code>import subprocess
  import struct
  
  door = subprocess.Popen(['python','B.py'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  door.stdin.write(struct.pack(&quot;&gt;B&quot;, 0))
  door.stdin.flush()
  print(struct.unpack(&quot;&gt;B&quot;, door.stdout.read()))
  </code></pre>
  <p><strong>B.py</strong></p>
  <pre><code>import sys
  import struct
  
  my_input = sys.stdin.buffer.read()
  nbr = struct.unpack(&quot;&gt;B&quot;, my_input)
  sys.stdout.buffer.write(struct.pack(&quot;&gt;B&quot;,nbr+1))
  sys.stdout.buffer.flush()
  </code></pre>