def get_external_subprocess_output(command_list, print_output=False, indent_string="",
                      split_lines=True, ignore_called_process_errors=False, env=None):
    """Run the command and arguments in the command_list.  Will search the system
    PATH.  Returns the output as a list of lines.   If print_output is True the
    output is echoed to stdout, indented (or otherwise prefixed) by indent_string.
    Waits for command completion.  Called process errors can be set to be
    ignored if necessary."""

    # Note ghostscript bounding box output writes to stderr!  So we need to
    # be sure to capture the stderr along with the stdout.

    print_output = False # Useful for debugging to set True.

    use_popen = True # Needs to be True to set ignore_called_process_errors True
    if use_popen: # Use lower-level Popen call.
        p = subprocess.Popen(command_list, stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT, env=env)
        output, errout = p.communicate()
        returncode = p.poll()
        if not ignore_called_process_errors and returncode != 0:
            raise subprocess.CalledProcessError(returncode, command_list, output=output)
    else: # Use a check_output call.
        # Note this does not work correctly if shell=True.
        output = subprocess.check_output(command_list, stderr=subprocess.STDOUT,
                                         shell=False, env=env)

    output = output.decode("utf-8")

    if split_lines or print_output:
        split_output = output.splitlines()
    if split_lines:
        output = split_output
    if print_output:
        print()
        for line in split_output:
            print(indent_string + line)
        sys.stdout.flush()
    return output
Run the command and arguments in the command_list.  Will search the system
    PATH.  Returns the output as a list of lines.   If print_output is True the
    output is echoed to stdout, indented (or otherwise prefixed) by indent_string.
    Waits for command completion.  Called process errors can be set to be
    ignored if necessary.