child = pexpect.spawn (\'/bin/bash\') child.sendline(\'ls\') print(child.readline()) print child.before, child.after
All I get with this code in my
I think all you need is:
p = pexpect.spawn('ls') p.expect(pexpect.EOF) print(p.before)
or
p = pexpect.spawn('/bin/ls') p.expect(pexpect.EOF) print(p.before)
p = pexpect.spawn('/bin/bash -c "ls"') p.expect(pexpect.EOF) print(p.before)
or even
print(pexpect.run('ls'))