child = pexpect.spawn (\'/bin/bash\')
child.sendline(\'ls\')
print(child.readline())
print child.before, child.after
All I get with this code in my
copy from class spawn(SpawnBase) docstring, maybe example-2 is what you want.
Example log input and output to a file::
child = pexpect.spawn('some_command')
fout = open('mylog.txt','wb')
child.logfile = fout
Example log to stdout::
# In Python 2:
child = pexpect.spawn('some_command')
child.logfile = sys.stdout
# In Python 3, we'll use the ``encoding`` argument to decode data
# from the subprocess and handle it as unicode:
child = pexpect.spawn('some_command', encoding='utf-8')
child.logfile = sys.stdout