'Handle a command and log the results.'

def handle_command(self, tool_dependency, cmd, return_output=False, job_name=''):

    command = str(cmd)
    output = self.handle_complex_command(command, job_name=job_name)
    self.log_results(cmd, output, os.path.join(self.install_dir, basic_util.INSTALLATION_LOG))
    stdout = output.stdout
    stderr = output.stderr
    if (len(stdout) > DATABASE_MAX_STRING_SIZE):
        log.warning(('Length    of    stdout    >    %s,    so    only    a    portion    will    be    saved    in    the    database.' % str(DATABASE_MAX_STRING_SIZE_PRETTY)))
        stdout = shrink_string_by_size(stdout, DATABASE_MAX_STRING_SIZE, join_by='\n..\n', left_larger=True, beginning_on_size_error=True)
    if (len(stderr) > DATABASE_MAX_STRING_SIZE):
        log.warning(('Length    of    stderr    >    %s,    so    only    a    portion    will    be    saved    in    the    database.' % str(DATABASE_MAX_STRING_SIZE_PRETTY)))
        stderr = shrink_string_by_size(stderr, DATABASE_MAX_STRING_SIZE, join_by='\n..\n', left_larger=True, beginning_on_size_error=True)
    if (output.return_code not in [0]):
        status = self.app.install_model.ToolDependency.installation_status.ERROR
        if stderr:
            error_message = unicodify(stderr)
        elif stdout:
            error_message = unicodify(stdout)
        else:
            error_message = ('Unknown    error    occurred    executing    shell    command    %s,    return_code:    %s' % (str(cmd), str(output.return_code)))
        tool_dependency_util.set_tool_dependency_attributes(self.app, tool_dependency=tool_dependency, status=status, error_message=error_message)
    if return_output:
        return output
    return output.return_code
