Pexpect eats bash prompt
Question: This expect script launches a bash shell that includes the prompt:

    
    
    #! /usr/bin/env expect
    
    spawn -noecho "bash"
    
    expect "$ "
    
    send "echo 'Hello, "
    
    interact
    

e.g. `user@host:/path/to/working/directory$ echo 'Hello,`

I tried doing the same thing with
[Pexpect](http://pexpect.readthedocs.org/en/latest/):

    
    
    #! /usr/bin/env python
    
    import pexpect
    
    child = pexpect.spawn('bash')
    
    index = child.expect("\$ ")
    
    child.send("echo 'Hello, ")
    
    child.interact()
    

However, it swallows the prompt and only shows `echo 'Hello,`. I can force
`bash` to repaint with `child.sendcontrol('l')`, but this only works for some
shells; [`dash`](http://gondor.apana.org.au/~herbert/dash/), for example, does
not support it.

    
    
    $ python
    Python 2.7.9 (default, Dec 11 2014, 08:58:12) 
    [GCC 4.9.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pexpect
    >>> pexpect.__version__
    '3.2'
    


Answer: As J.F. Sebastian indicated, there is an alternative:

    
    
    #! /usr/bin/env python
    import pexpect
    import sys
    child = pexpect.spawn('bash')
    child.logfile_read = sys.stdout
    index = child.expect_exact("$ ")
    child.interact()
    

