In pexpect, the before attribute contains all the output received before the expected pattern (e.g., PROMPT) is matched. When you use sendline, the command you send is echoed back by the terminal (e.g., adb shell), which is why it appears in before.
How to Avoid sendline Argument in before
To exclude the command itself from before, you have a few options:
1. Use send + Manual Newline
Instead of sendline, use send and manually add a newline (\r or \n). This avoids pexpect automatically echoing the command in some terminal emulators.