def METHOD_NAME(
    cmdline: List[str], env: Dict[str, str], write_pid_to: Optional[str] = None
) -> Tuple[List[str], Dict[str, str]]:
    """
    Ideally only this function is actually used from this module.
    It receives an existing command line and environment and provides a new
    command line and environment to be used depending which should have the
    same effect when running.
    :param write_pid_to: if passed, the launch will be made in a way that
        a wrapper script is used to launch the script and then write the
        pid of the launched executable to the passed file.
    """
    if write_pid_to:
        cmdline, env = _update_command_line_to_write_pid(cmdline, env, write_pid_to)
        embed_args = 3
    else:
        embed_args = 1
    if disable_launch_env_script():
        return cmdline, env
    set_env_and_run_code = create_run_with_env_code(env, cmdline[:embed_args])
    if len(set_env_and_run_code) > 240:
        script_path = _compute_path_for_env()
        write_as_script(set_env_and_run_code, script_path)
        new_cmdline = [str(script_path)] + cmdline[embed_args:]
        return new_cmdline, {}
    return cmdline, env