<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_run(self, args, workingDir=None, output_dir=None, result_files_patterns=[], rootDir=None, environ=os.environ.copy()):
 """ This method executes the command line and waits for the termination of it, handling all setup and cleanup. @param args: the command line to run @param rootDir: None or a root directory that contains all relevant files for starting a new process @param workingDir: None or a directory which the execution should use as working directory @param output_dir: the directory where to write result files (required if result_files_pattern) @param result_files_patterns: a list of patterns of files to retrieve as result files """

        # preparations
        temp_dir = None
        if rootDir is None:
            temp_dir = tempfile.mkdtemp(prefix="Benchexec_run_")

        pid = None
        returnvalue = 0

        logging.debug('Starting process.')

        try:
            pid, result_fn = self._start_execution(args=args,
                stdin=None, stdout=None, stderr=None,
                env=environ, root_dir=rootDir, cwd=workingDir, temp_dir=temp_dir,
                cgroups=Cgroup({}),
                output_dir=output_dir, result_files_patterns=result_files_patterns,
                child_setup_fn=util.dummy_fn,
                parent_setup_fn=util.dummy_fn,
                parent_cleanup_fn=util.dummy_fn)

            with self.SUB_PROCESS_PIDS_LOCK:
                self.SUB_PROCESS_PIDS.add(pid)

            returnvalue, unused_ru_child, unused = result_fn() # blocks until process has terminated

        finally:
            # cleanup steps that need to get executed even in case of failure
            logging.debug('Process terminated, exit code %s.', returnvalue)

            with self.SUB_PROCESS_PIDS_LOCK:
                self.SUB_PROCESS_PIDS.discard(pid)

            if temp_dir is not None:
                logging.debug('Cleaning up temporary directory.')
                util.rmtree(temp_dir, onerror=util.log_rmtree_error)

        # cleanup steps that are only relevant in case of success
        return util.ProcessExitCode.from_raw(returnvalue)