title: reading output from pexpect sendline
body: <p>I have pexpect working, but I am having problems printing the output back from it.  In my test script below, it creates the ssh connection, and then sends a sudo su -, then my password, and then sends a line that would require sudo access to do (I have also added p.interact() a few times to make sure it is at root).  The problem I am having, is with returning the output of the commands I run.  In the end I am wanting to run some top commands, and some du -h, and other(much more complex) space commands. But currently when it tries to print p.before, I get:</p>
  
  <pre><code>Traceback (most recent call last):
  File "./ssh.py", line 37, in &lt;module&gt;
  print p.before()
  TypeError: 'str' object is not callable
  </code></pre>
  
  <p>Here is the script I am working from(edited to remove my pass and such)</p>
  
  <pre><code>#!/usr/bin/env python
  
  import pexpect
  import struct, fcntl, os, sys, signal
  
  def sigwinch_passthrough (sig, data):
      # Check for buggy platforms (see pexpect.setwinsize()).
      if 'TIOCGWINSZ' in dir(termios):
          TIOCGWINSZ = termios.TIOCGWINSZ
      else:
          TIOCGWINSZ = 1074295912 # assume
      s = struct.pack ("HHHH", 0, 0, 0, 0)
      a = struct.unpack ('HHHH', fcntl.ioctl(sys.stdout.fileno(), TIOCGWINSZ , s))
      global global_pexpect_instance
      global_pexpect_instance.setwinsize(a[0],a[1])
  
  ssh_newkey = 'Are you sure you want to continue connecting'
  p=pexpect.spawn('ssh user@localhost')
  i=p.expect([ssh_newkey,'password:',pexpect.EOF,pexpect.TIMEOUT],1)
  if i==0:
      print "I say yes"
      p.sendline('yes')
      i=p.expect([ssh_newkey,'password:',pexpect.EOF])
  if i==1:
      print "I give password",
      p.sendline("mypassword")
  elif i==2:
      print "I either got key or connection timeout"
      pass
  elif i==3: #timeout
      pass
  global global_pexpect_instance
  global_pexpect_instance = p
  p.sendline("sudo su -")
  p.sendline("mypasswd")
  p.sendline("mkdir /home/user/test")
  print p.before
  </code></pre>
  
  <p>I am working off of this link: <a href="http://linux.byexamples.com/archives/346/python-how-to-access-ssh-with-pexpect/" rel="nofollow">http://linux.byexamples.com/archives/346/python-how-to-access-ssh-with-pexpect/</a></p>
  
  <p>Any help is much appreciated.</p>
  
  <p>EDIT:  As  Armin Rigo pointed out below. I was calling to p.before as a function like p.before().  Stupid mistake on my part, as this explains why I was getting this error today, and not yesterday when I was trying this.  After making that change to my script, and modifying the command being sent, print p.before, and no output is returned.  Any other ways to return output from a sendline() command?</p>