This doesn't seem right - we're doing this before we've disconnected from the original terminal, so stdin is still connected to the tty where the parent is running, not the new tty Pexpect has created. Am I missing something? There should at least be a comment explaining what's going on.