parameters: (cmd, use_file=False)
return_statement: return proc
docstring: Start command and returns proc instance from Popen.
docstring_summary: Start command and returns proc instance from Popen.
docstring_tokens: Start command and returns proc instance from Popen .
function: def start_cmd(cmd, use_file=False):
      """Start command and returns proc instance from Popen."""
  
      orig_cmd = ""
      # Multi-commands need to be written to a temporary file to execute on Windows.
      # This is due to complications with invoking Bash in Windows.
      if use_file:
          orig_cmd = cmd
          temp_file = create_temp_executable_file(cmd)
          # The temporary file name will have '\' on Windows and needs to be converted to '/'.
          cmd = "bash -c {}".format(temp_file.replace("\\", "/"))
  
      # If 'cmd' is specified as a string, convert it to a list of strings.
      if isinstance(cmd, str):
          cmd = shlex.split(cmd)
  
      if use_file:
          LOGGER.debug("Executing '%s', tempfile contains: %s", cmd, orig_cmd)
      else:
          LOGGER.debug("Executing '%s'", cmd)
  
      # We use psutil.Popen() rather than subprocess.Popen() in order to cache the creation time of
      # the process. This enables us to reliably detect pid reuse in kill_process().
      proc = psutil.Popen(cmd, close_fds=True)
      LOGGER.debug("Spawned process %s pid %d", proc.name(), proc.pid)
  
      return proc
function_tokens: def start_cmd ( cmd , use_file = False ) : orig_cmd = "" # Multi-commands need to be written to a temporary file to execute on Windows. # This is due to complications with invoking Bash in Windows. if use_file : orig_cmd = cmd temp_file = create_temp_executable_file ( cmd ) # The temporary file name will have '\' on Windows and needs to be converted to '/'. cmd = "bash -c {}" . format ( temp_file . replace ( "\\" , "/" ) ) # If 'cmd' is specified as a string, convert it to a list of strings. if isinstance ( cmd , str ) : cmd = shlex . split ( cmd ) if use_file : LOGGER . debug ( "Executing '%s', tempfile contains: %s" , cmd , orig_cmd ) else : LOGGER . debug ( "Executing '%s'" , cmd ) # We use psutil.Popen() rather than subprocess.Popen() in order to cache the creation time of # the process. This enables us to reliably detect pid reuse in kill_process(). proc = psutil . Popen ( cmd , close_fds = True ) LOGGER . debug ( "Spawned process %s pid %d" , proc . name ( ) , proc . pid ) return proc