title: Read stdout from subprocess until there is nothing left
body: <p>I would like to run several commands in the same shell. After some research I found that I could keep a shell open using the return process from <code>Popen</code>. I can then write and read to <code>stdin</code> and <code>stdout</code>. I tried implementing it as such:</p>
  
  <pre><code>process = Popen(['/bin/sh'], stdin=PIPE, stdout=PIPE)
  process.stdin.write('ls -al\n')
  out = ' '
  while not out == '':
      out = process.stdout.readline().rstrip('\n')
      print out
  </code></pre>
  
  <p>Not only is my solution ugly, it doesn't work. <code>out</code> is never empty because it hands on the <code>readline()</code>. How can I successfully end the <code>while</code> loop when there is nothing left to read?</p>