Question
How do you get the output of a command with multiple lines of output using pexpect?
Example
This code works, albeit with the output smashed into one line:
child = pexpect.spawn('ping -c 3 1.1.1.1')
child.expect(pexpect.EOF)
print(child.before)
However, this code does not work:
child = pexpect.spawn('hostname')
child.expect(pexpect.EOF)
print(child.before)
child.seldline('ping -c 3 1.1.1.1')
child.expect(pexpect.EOF)
print(child.before)
How would I get this second code to work?
Background
I have commands that I need to run to get connected (replaced here with hostname) and then commands that output mulitiple lines (replaced here with ping) that I cannot seem to get the output from. If I look for any string other than EOF, I get an EOF exception...
The commands I am actually running are here if you need proof:
The answer in this other question may be deprecated because this section of code copied exactly just outputs b''
over and over again.