child = pexpect.spawn ('/bin/bash')
child.sendline('ls')
print(child.readline())
print child.before, child.after
All I get with this code in my output is
ls
ls
But when my code is
child = pexpect.spawn('ls')
print(child.readline())
print child.before, child.after
Then it works, but only for the first 2 prints. Am I using the wrong send command? I tried send, write, sendline, and couldn't find anymore.
I think all you need is:
or
or
or even
go to open your logfile:- go to terminal
Try the following:
The
read()
will give you the entire output of the ls.copy from class spawn(SpawnBase) docstring, maybe example-2 is what you want.
Example log input and output to a file::
Example log to stdout::
In pexpect the before and after attributes are populated after an expect method. The most common thing used in this situation is waiting for the prompt (so you'll know that the previous command finished execution). So, in your case, the code might look something like this:
See the manual entry on the subject.