def call_and_wait_tool(command, tool_name, input = '', on_result = None, filename = None, on_line = None, check_enabled = True, **popen_kwargs):
    tool_enabled = 'enable_{0}'.format(tool_name)

    if check_enabled and get_setting_async(tool_enabled) != True:
        return None
    extended_env = get_extended_env()

    source_dir = get_source_dir(filename)

    def mk_result(s):
        return on_result(s) if on_result else s

    try:
        if on_line:
            p = call_and_wait_with_input(command, input, wait = False, cwd = source_dir, **popen_kwargs)
            for l in p.stdout:
                on_line(mk_result(crlf2lf(decode_bytes(l))))
            exit_code = p.wait()
            if exit_code != 0:
                raise Exception('{0} exited with exit code {1} and stderr: {2}'.format(tool_name, exit_code, p.stderr.read()))
        else:
            exit_code, out, err = call_and_wait_with_input(command, input, cwd = source_dir, **popen_kwargs)
            out = crlf2lf(out)

            if exit_code != 0:
                raise Exception('{0} exited with exit code {1} and stderr: {2}'.format(tool_name, exit_code, err))

            return mk_result(out)

    except __HOLE__ as e:
        if e.errno == errno.ENOENT:
            output_error_async(sublime.active_window(), "SublimeHaskell: {0} was not found!\n'{1}' is set to False".format(tool_name, tool_enabled))
            set_setting_async(tool_enabled, False)
        else:
            log('{0} fails with {1}, command: {2}'.format(tool_name, e, command), log_error)

        return None

    except Exception as e:
        log('{0} fails with {1}, command: {2}'.format(tool_name, e, command), log_error)

    return None
dataset/ETHPy150Open SublimeHaskell/SublimeHaskell/sublime_haskell_common.py/call_and_wait_tool