Since you are hitting the EOF then you can have code like this:
index = pexpect.expect(['test', pexpect.EOF, pexpect.TIMEOUT])
if index == 0:
do_something()
elif index == 1:
print(pexpect.before)
elif index == 1:
print(pexpect.before)
I expect that if you expect the EOF that you will be able to use .before attribute.
Alternatively: You can execute the command and pipe it's output to a file then download the file and work with it locally.
and if you want you can gain control manually by using pexpect.interact()