code: def exec_cmd(
      cmd: List[str],
      throw_on_error: bool = True,
      logger: Optional[logging.Logger] = None,
  ) -> Union[int, Tuple[int, str, str]]:
      """
      Runs a command as a child process.
  
      A convenience wrapper for running a command from a Python script.
  
      Note on the return value: A tuple of the exit code,
      standard output and standard error is returned.
  
      Args:
          cmd: the command to run, as a list of strings
          throw_on_error: if true, raises an Exception if the exit code of the
              program is nonzero
      """
      child = subprocess.Popen(
          cmd,
          stdout=subprocess.PIPE,
          stdin=subprocess.PIPE,
          stderr=subprocess.PIPE,
          universal_newlines=True,
      )
      (stdout, stderr) = child.communicate()
      exit_code = child.wait()
      if throw_on_error and exit_code != 0:
          raise ShellCommandException(
              "Non-zero exit code: %s\n\nSTDOUT:\n%s\n\nSTDERR:%s"
              % (exit_code, stdout, stderr)
          )
      return exit_code, stdout, stderr
  
file_path: ray/python/ray/_private/runtime_env/conda_utils.py
imports: import logging
  import os
  import shutil
  import subprocess
  import hashlib
  import json
  from typing import Optional, List, Union, Tuple
label_desc: Use image node_id 7 for calling a global function with example usage: exec_cmd(cmd, throw_on_error, logger) and returns: exit_code,  stdout,  stderr