def METHOD_NAME(cmd, env=None, cwd=None, allow_fail: bool = False, log_file=None) -> int:
    def log_to_stdout(msg):
        sys.stdout.buffer.write(msg.encode(errors="surrogateescape"))
    if log_file is not None:
        with open(log_file, "a", encoding="utf-8", errors="surrogateescape") as log:
            def log_function(msg):
                log.write(msg)
                log_to_stdout(msg)
            return _run_cmd(
                cmd, env=env, cwd=cwd, allow_fail=allow_fail, log_fn=log_function
            )
    else:
        return _run_cmd(
            cmd, env=env, cwd=cwd, allow_fail=allow_fail, log_fn=log_to_stdout
        )