无法使用预期的 child.before 获取数据

Unable to get data using child.before in pexpect

    ip="99.78.992.02"
    prompt="$"
    log_file_handle = open(os.path.join(os.getcwd(), "log_file"),"a")
    child = pexpect.spawn("ssh abc@%s" % ip, logfile=log_file_handle) # this works because I have public-private key set up
    child.sendline("ls -l")
    child.expect(prompt)
    print "child.before %s" % child.before
    print "child.after %s" % child.after

我得到的回复是:

    child.before  
    Welcome to Ubuntu 12.04.5 LTS (GNU/Linux 3.2.0-67-generic-pae i686)

     * Documentation:  https://help.ubuntu.com/

    360 packages can be updated.
    305 updates are security updates.

    New release '14.04.1 LTS' available.
    Run 'do-release-upgrade' to upgrade to it.



    *** /dev/sda4 will be checked for errors at next reboot ***
    *** /dev/sda2 will be checked for errors at next reboot ***

    No mail.
    Last login: Wed Mar  4 13:44:40 2015 from 10.49.92.49
    ls
    abc@mycomputer:~
    child.after $

为什么我在 child.before 中得不到 "ls -l" 的输出?有人可以对此发表评论吗?

如J.F。塞巴斯蒂安在评论中说,我必须等待提示才能发出命令。