Replace subprocess with pexpect