'Execute command_string on the SSH channel using a pattern-based mechanism. Generally
used for show commands. By default this method will keep waiting to receive data until the
network device prompt is detected. The current network device prompt will be determined
automatically.
:param command_string: The command to be executed on the remote device.
:type command_string: str
:param expect_string: Regular expression pattern to use for determining end of output.
If left blank will default to being based on router prompt.
:type expect_str: str
:param delay_factor: Multiplying factor used to adjust delays (default: 1).
:type delay_factor: int
:param max_loops: Controls wait time in conjunction with delay_factor (default: 150).
:type max_loops: int
:param strip_prompt: Remove the trailing router prompt from the output (default: True).
:type strip_prompt: bool
:param strip_command: Remove the echo of the command from the output (default: True).
:type strip_command: bool
:param normalize: Ensure the proper enter is sent at end of command (default: True).
:type normalize: bool'

def send_command(self, command_string, expect_string=None, delay_factor=1, max_loops=500, auto_find_prompt=True, strip_prompt=True, strip_command=True, normalize=True):

    delay_factor = self.select_delay_factor(delay_factor)
    if (expect_string is None):
        if auto_find_prompt:
            try:
                prompt = self.find_prompt(delay_factor=delay_factor)
            except ValueError:
                prompt = self.base_prompt
        else:
            prompt = self.base_prompt
        search_pattern = re.escape(prompt.strip())
    else:
        search_pattern = expect_string
    if normalize:
        command_string = self.normalize_cmd(command_string)
    time.sleep((delay_factor * 0.2))
    self.clear_buffer()
    self.write_channel(command_string)
    i = 1
    output = u''
    while (i <= max_loops):
        new_data = self.read_channel()
        if new_data:
            output += new_data
            try:
                lines = output.split(u'\n')
                first_line = lines[0]
                if (BACKSPACE_CHAR in first_line):
                    pattern = (search_pattern + u'.*$')
                    first_line = re.sub(pattern, repl=u'', string=first_line)
                    lines[0] = first_line
                    output = u'\n'.join(lines)
            except IndexError:
                pass
            if re.search(search_pattern, output):
                break
        else:
            time.sleep((delay_factor * 0.2))
        i += 1
    else:
        raise IOError(u'Search    pattern    never    detected    in    send_command_expect:    {0}'.format(search_pattern))
    output = self._sanitize_output(output, strip_command=strip_command, command_string=command_string, strip_prompt=strip_prompt)
    return output
