title: Python subprocess stdout.readlines() getting stuck
body: <p>I am trying to use to python subprocess module in order to ssh to a server and then switch to a super user and then ls and print the folders in the terminal.</p>
  
  <p>My Code:</p>
  
  <pre><code>def sudo_Test():
      HOST = 'Host'
      PORT = '227'
      USER = 'user'
      cmd='sudo su - ec2-user;ls'
  
      process = subprocess.Popen(['ssh','-tt','{}@{}'.format(USER, HOST),
                              '-p',PORT,cmd],
                             shell=False,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             stdin=subprocess.PIPE)
      process.stdin.write("my_password\r\n")
  
      print "stuck here VVV"
      result = process.stdout.readlines()
      print "finished it"
  
      if not result:
          print "Im an error"
          err = process.stderr.readlines()
          print('ERROR: {}'.format(err))
      else:
          print "I'm a success"
          print result
  
  print sudo_Test()
  </code></pre>
  
  <p>Console output when I run this:</p>
  
  <pre><code>dredbounds-computer:folder dredbound$ python terminal_test.py
  stuck here VVV
  </code></pre>
  
  <p>For some reason the code gets stuck on the line result = process.stdout.readlines(). I have to cntrl+c to exit out of the terminal session when this happens. It works fine if I just do cmd='sudo; ls' instead of cmd='sudo su - ec2-user;ls'.Anyone know what I'm doing wrong or how I can get this to work?</p>
  
  <p>Update:
  I changed cmd='sudo su - ec2-user;ls' -> cmd='sudo su - ec2-user ls' in the code above. Now I am getting the following error:</p>
  
  <pre><code>['password\r\n', '\r\n', '/bin/ls: /bin/ls: cannot execute binary   file\r\n']
  </code></pre>
  
  <p>I'm not sure why it thinks ls is a binary file now, but is there anyway i can tell it that it is just a terminal command so it returns a list of directories?</p>