code: def _run_app_command(app_name: str, app_id: Optional[str]):
      """Execute a function in a running App from its name."""
      # 1: Collect the url and comments from the running application
      _clean_lightning_connection()
  
      running_help = _is_running_help(sys.argv)
  
      retriever = _LightningAppOpenAPIRetriever(
          app_id, use_cache=running_help
      )
  
      if not running_help and (
          retriever.url is None or retriever.api_commands is None
      ):
          if app_name == "localhost":
              print(
                  "The command couldn't be executed as your local Lightning App isn't running."
              )
          else:
              print(
                  f"The command couldn't be executed as your cloud Lightning App `{app_name}` isn't running."
              )
          sys.exit(0)
  
      if not retriever.api_commands:
          raise Exception(
              "This application doesn't expose any commands yet."
          )
  
      full_command = "_".join(sys.argv)
  
      has_found = False
      for command in list(retriever.api_commands):
          if command in full_command:
              has_found = True
              for value in sys.argv:
                  if value == command and "_" in value:
                      print(
                          f"The command `{value}` was provided with an underscore and it isn't allowed."
                          f"Instead, use `lightning {value.replace('_', ' ')}`."
                      )
                      sys.exit(0)
              break
  
      if not has_found:
          raise Exception(
              f"The provided command isn't available in {list(retriever.api_commands)}"
          )
  
      # 2: Send the command from the user
      metadata = retriever.api_commands[command]
  
      try:
          # 3: Execute the command
          if metadata["tag"] == OpenAPITags.APP_COMMAND:
              _handle_command_without_client(
                  command, metadata, retriever.url
              )
          else:
              _handle_command_with_client(
                  command, metadata, app_name, app_id, retriever.url
              )
      except ModuleNotFoundError:
          _install_missing_requirements(retriever, fail_if_missing=True)
  
      if running_help:
          print("Your command execution was successful.")
  
file_path: pytorch-lightning/src/lightning/app/cli/commands/app_commands.py
imports: import os
  import sys
  from typing import Dict, Optional
  import requests
  from lightning.app.cli.connect.app import _clean_lightning_connection, _install_missing_requirements, _resolve_command_path
  from lightning.app.utilities.cli_helpers import _LightningAppOpenAPIRetriever
  from lightning.app.utilities.commands.base import _download_command
  from lightning.app.utilities.enum import OpenAPITags
label_desc: Use image node_id 2 for calling a global function with example usage: _run_app_command(app_name, app_id) without return types