code: def _do_run(cmd, checks, log_stdout=False):
      
      cmd, shell_arg, executable_arg = _normalize_cmd_args(cmd)
      s = subprocess.Popen(cmd, shell=shell_arg, executable=executable_arg,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.STDOUT, close_fds=True)
      debug_stdout = collections.deque(maxlen=100)
      while 1:
          line = s.stdout.readline()
          if line:
              debug_stdout.append(line)
              if log_stdout:
                  logger.debug(line.rstrip())
              else:
                  logger.debug(line.rstrip())
          exitcode = s.poll()
          if exitcode is not None:
              for line in s.stdout:
                  debug_stdout.append(line)
              if exitcode is not None and exitcode != 0:
                  error_msg = " ".join(cmd) if not isinstance(cmd, basestring) else cmd
                  error_msg += "\n"
                  error_msg += "".join(debug_stdout)
                  s.communicate()
                  s.stdout.close()
                  raise subprocess.CalledProcessError(exitcode, error_msg)
              else:
                  break
      s.communicate()
      s.stdout.close()
      # Check for problems not identified by shell return codes
      if checks:
          for check in checks:
              if not check():
                  raise IOError("External command failed")
docs: Perform running and check results, raising errors for issues.