How to get the last line of output with pexpect
<p>I'm trying to get the last line (after sending the command) and only the last line of the output with pexpect. command here is a parameter of the function.</p>

<pre><code>child.sendline(command)
child.expect(command + '\r\n')

return child.after.decode("utf-8").rstrip()
</code></pre>

<p>This is the type of commands I send :</p>

<pre><code>qdbus com.company.menu /Menu ParamName
</code></pre>

<p>I should receive an output like this (it can have spaces between words and without the linux username and hostname): </p>

<p>Words* (newline)</p>

<p>Right now it outputs the command itself.</p>

<p>What is wrong the my regex in the expect method?</p>