Python how to read output from pexpect child?

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:

child = pexpect.spawn ('/bin/bash')
child.expect("Your bash prompt here")
child.sendline('ls')
#If you are using pxssh you can use this
#child.prompt()
child.expect("Your bash prompt here")
print(child.before)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)