<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def execute(self, app_path, app_args, version, **kwargs):
 """ The execute functon of the hook will be called to start the required application :param app_path: (str) The path of the application executable :param app_args: (str) Any arguments the application may require :param version: (str) version of the application being run if set in the "versions" settings of the Launcher instance, otherwise None :returns: (dict) The two valid keys are 'command' (str) and 'return_code' (int). """


        multi_launchapp = self.parent
        extra = multi_launchapp.get_setting("extra")

        use_rez = False
        if self.check_rez():
            from rez.resolved_context import ResolvedContext
            from rez.config import config

            # Define variables used to bootstrap tank from overwrite on first reference
            # PYTHONPATH is used by tk-maya
            # NUKE_PATH is used by tk-nuke
            # HIERO_PLUGIN_PATH is used by tk-nuke (nukestudio)
            # KATANA_RESOURCES is used by tk-katana
            config.parent_variables = ["PYTHONPATH", "HOUDINI_PATH", "NUKE_PATH", "HIERO_PLUGIN_PATH", "KATANA_RESOURCES"]

            rez_packages = extra["rez_packages"]
            context = ResolvedContext(rez_packages)

            use_rez = True

        system = sys.platform
        shell_type = 'bash'
        if system == "linux2":
            # on linux, we just run the executable directly
            cmd = "%s %s &" % (app_path, app_args)

        elif self.parent.get_setting("engine") in ["tk-flame", "tk-flare"]:
            # flame and flare works in a different way from other DCCs
            # on both linux and mac, they run unix-style command line
            # and on the mac the more standardized "open" command cannot
            # be utilized.
            cmd = "%s %s &" % (app_path, app_args)

        elif system == "darwin":
            # on the mac, the executable paths are normally pointing
            # to the application bundle and not to the binary file
            # embedded in the bundle, meaning that we should use the
            # built-in mac open command to execute it
            cmd = "open -n \"%s\"" % (app_path)
            if app_args:
                cmd += " --args \"%s\"" % app_args.replace("\"", "\\\"")

        elif system == "win32":
            # on windows, we run the start command in order to avoid
            # any command shells popping up as part of the application launch.
            cmd = "start /B \"App\" \"%s\" %s" % (app_path, app_args)
            shell_type = 'cmd'

        # Execute App in a Rez context
        if use_rez:
            n_env = os.environ.copy()
            proc = context.execute_shell(
                command=cmd,
                parent_environ=n_env,
                shell=shell_type,
                stdin=False,
                block=False
            )
            exit_code = proc.wait()
            context.print_info(verbosity=True)

        else:
            # run the command to launch the app
            exit_code = os.system(cmd)

        return {
            "command": cmd,
            "return_code": exit_code
        }