def _do_run(cmd, checks, log_stdout=False):
cmd, shell_arg, executable_arg = _normalize_cmd_args(cmd)<EOL>s = subprocess.Popen(cmd, shell=shell_arg, executable=executable_arg,<EOL>stdout=subprocess.PIPE,<EOL>stderr=subprocess.STDOUT, close_fds=True)<EOL>debug_stdout = collections.deque(maxlen=<NUM_LIT:100>)<EOL>while <NUM_LIT:1>:<EOL><INDENT>line = s.stdout.readline()<EOL>if line:<EOL><INDENT>debug_stdout.append(line)<EOL>if log_stdout:<EOL><INDENT>logger.debug(line.rstrip())<EOL><DEDENT>else:<EOL><INDENT>logger.debug(line.rstrip())<EOL><DEDENT><DEDENT>exitcode = s.poll()<EOL>if exitcode is not None:<EOL><INDENT>for line in s.stdout:<EOL><INDENT>debug_stdout.append(line)<EOL><DEDENT>if exitcode is not None and exitcode != <NUM_LIT:0>:<EOL><INDENT>error_msg = "<STR_LIT:U+0020>".join(cmd) if not isinstance(cmd, basestring) else cmd<EOL>error_msg += "<STR_LIT:\n>"<EOL>error_msg += "<STR_LIT>".join(debug_stdout)<EOL>s.communicate()<EOL>s.stdout.close()<EOL>raise subprocess.CalledProcessError(exitcode, error_msg)<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>s.communicate()<EOL>s.stdout.close()<EOL>if checks:<EOL><INDENT>for check in checks:<EOL><INDENT>if not check():<EOL><INDENT>raise IOError("<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT>
Perform running and check results, raising errors for issues.