title: python subprocess - How to check if there is not any new data in the PIPE?
body: <p>I have the following example:</p>
  
  <pre><code>import subprocess
  
  p = subprocess.Popen("cmd",stdin = subprocess.PIPE, stdout=subprocess.PIPE )
  p.stdin.write(b'cd\\' + b'\r\n')
  p.stdin.write(b'dir' + b'\r\n')
  p.stdin.write(b'\r\n')
  
  
  
  while True:
      line = p.stdout.readline()
      print(line.decode('ascii'), end='')
      if line.rstrip().decode('ascii') == 'C:\&gt;': #I need to check at this point if there is new data in the PIPE
          print('End of File')
          break
  </code></pre>
  
  <p>I am listening to the PIPE for any output from the subprocess and if there is not any new data coming through the PIPE I would like to stop reading. I would like to have a control statement that would tell me that PIPE is empty. This would help me to avoid problems in case my process freezes or ends with an unexpected result. </p>