Block and print the output of the command

        Raises:
            TypeError: If command is blocking
762460
def print_live_output(self):
        '''
        
        '''
        if self.block:
            raise TypeError(NON_BLOCKING_ERROR_MESSAGE)
        else:
            while self.thread.is_alive() or self.old_output_size < len(self.output) or self.old_error_size < len(self.error):
                if self._stdout is not None and len(self.output) > self.old_output_size:
                    while self.old_output_size < len(self.output):
                        self.logger.info(self.output[self.old_output_size])
                        self.old_output_size += 1

                if self._stderr is not None and len(self.error) > self.old_error_size:
                    while self.old_error_size < len(self.error):
                        self.logger.error(self.error[self.old_error_size])
                        self.old_error_size += 1
618435
def call_block(block,stdout,stderr,exitstatus)
      # blocks that take no arguments have arity -1.  Or 0.  Ugh.
      if block.arity > 0
        case block.arity
        when 1 
          block.call(stdout)
        when 2
          block.call(stdout,stderr)
        else
          # Let it fail for lambdas
          block.call(stdout,stderr,exitstatus)
        end
      else
        block.call
      end
    end
782424
def subprocess_output(command, raise_on_empty_output):
    

    # Use tempfile, allowing a larger amount of memory. The subprocess.Popen
    # docs warn that the data read is buffered in memory. They suggest not to
    # use subprocess.PIPE if the data size is large or unlimited.
    with tempfile.TemporaryFile() as stdout_f, tempfile.TemporaryFile() as stderr_f:
        proc = subprocess.Popen(command, stdout=stdout_f, stderr=stderr_f)
        proc.wait()
        stderr_f.seek(0)
        err = stderr_f.read()
        stdout_f.seek(0)
        output = stdout_f.read()

    if not output and raise_on_empty_output:
        raise SubprocessOutputEmptyError("get_subprocess_output expected output but had none.")

    return output, err, proc.returncode
171260
def run_command(git_cmd, &block)
      if block_given?
        return IO.popen(git_cmd, &block)
      else
        return `#{git_cmd}`.chomp
      end
    end
729541
def _at_print(self, calculator, rule, scope, block):
        
        value = calculator.calculate(block.argument)
        sys.stderr.write("%s\n" % value)
1040505
def _run_command(self, env):
        
        output = ""
        urgent = False
        # run the block/command
        for command in self.commands:
            try:
                process = Popen(
                    command,
                    stdout=PIPE,
                    stderr=PIPE,
                    universal_newlines=True,
                    env=env,
                    shell=True,
                )
            except Exception as e:
                msg = "Command '{cmd}' {error}"
                raise Exception(msg.format(cmd=command, error=e))

            _output, _error = process.communicate()
            if self.py3.is_python_2():
                _output = _output.decode("utf-8")
                _error = _error.decode("utf-8")
            retcode = process.poll()

            # return code of 33 means urgent
            _urgent = retcode == 33

            if retcode and retcode != 33 or _error:
                msg = "i3block command '{cmd}' had an error see log for details."
                msg = msg.format(cmd=command)
                self.py3.notify_user(msg, rate_limit=None)
                msg = "i3block command '{cmd}' had error {error} returned {retcode}"
                msg = msg.format(cmd=command, error=_error, retcode=retcode)
                if hash(msg) not in self.errors:
                    self.py3.log(msg, level=self.py3.LOG_ERROR)
                    self.errors.append(hash(msg))
                _output = "Error\nError\n{}".format(
                    self.py3.COLOR_ERROR or self.py3.COLOR_BAD
                )
            # we have got output so update the received output
            # this provides support for i3blocks pseudo click support
            if _output:
                output = _output
                urgent = _urgent
        return output, urgent
727944
def getOutput(self):
        
        output = self.stdout
        if self.stdout:
            output += '\r\n'
        output += self.stderr
        return output
1035440
def _run_cmd(self, command):
        
        if self.throttle:
            tables = self.engine.describe_all(False)
            limiter = self.throttle.get_limiter(tables)
        else:
            limiter = None
        self.engine.rate_limit = limiter
        results = self.engine.execute(command)
        if results is None:
            pass
        elif isinstance(results, basestring):
            print(results)
        else:
            with self.display() as ostream:
                formatter = FORMATTERS[self.conf["format"]](
                    results,
                    ostream,
                    pagesize=self.conf["pagesize"],
                    width=self.conf["width"],
                )
                formatter.display()
        print_count = 0
        total = None
        for (cmd_fragment, capacity) in self.engine.consumed_capacities:
            total += capacity
            print(cmd_fragment)
            print(indent(str(capacity)))
            print_count += 1
        if print_count > 1:
            print("TOTAL")
            print(indent(str(total)))
981569
def after_output(command_status):
    
    if command_status not in range(256):
        raise ValueError("command_status must be an integer in the range 0-255")
    sys.stdout.write(AFTER_OUTPUT.format(command_status=command_status))
    # Flushing is important as the command timing feature maybe based on
    # AFTER_OUTPUT in the future.
    sys.stdout.flush()
1113644
def do_status(self, _):
        '''  '''
        server_status = self.server.is_server_running()
        if server_status == 'yes':
            print 'Server: ' + colorize('currently online', 'green')
        elif server_status == 'no':
            print 'Server: ' + colorize('currently offline', 'red')
        elif server_status == 'maybe':
            print 'Server: ' + colorize('status unknown', 'yellow')
        elif server_status == 'blocked':
            print 'Server: ' + colorize('blocked', 'red')
834533
def do_blockrep(self, line):
        """"""
        mns = self._split_args(line, 1, -1)
        self._command_processor.get_session().get_replication_policy().add_blocked(mns)
        self._print_info_if_verbose(
            "Set {} as blocked replication target(s)".format(", ".join(mns))
        )
323618
def print_lines(process: Popen) -> None:
    
    out, err = process.communicate()
    if out:
        for line in out.decode("utf-8").splitlines():
            print(line)
    if err:
        for line in err.decode("utf-8").splitlines():
            print(line)
707952
def get_cmd_output(*args, encoding: str = SYS_ENCODING) -> str:
    
    log.debug("get_cmd_output(): args = {!r}", args)
    p = subprocess.Popen(args, stdout=subprocess.PIPE)
    stdout, stderr = p.communicate()
    return stdout.decode(encoding, errors='ignore')
1010884
def poll_output(self):
        
        if self.block:
            return self.output

        new_list = self.output[self.old_output_size:]
        self.old_output_size += len(new_list)
        return new_list
175485
def process_block(self, block):
        
        ret = []
        output = None
        input_lines = None
        lineno = self.IP.execution_count

        input_prompt = self.promptin % lineno
        output_prompt = self.promptout % lineno
        image_file = None
        image_directive = None

        found_input = False
        for token, data in block:
            if token == COMMENT:
                out_data = self.process_comment(data)
            elif token == INPUT:
                found_input = True
                (out_data, input_lines, output, is_doctest,
                 decorator, image_file, image_directive) = \
                          self.process_input(data, input_prompt, lineno)
            elif token == OUTPUT:
                if not found_input:

                    TAB = ' ' * 4
                    linenumber = 0
                    source = 'Unavailable'
                    content = 'Unavailable'
                    if self.directive:
                        linenumber = self.directive.state.document.current_line
                        source = self.directive.state.document.current_source
                        content = self.directive.content
                        # Add tabs and join into a single string.
                        content = '\n'.join([TAB + line for line in content])

                    e = ('\n\nInvalid block: Block contains an output prompt '
                         'without an input prompt.\n\n'
                         'Document source: {0}\n\n'
                         'Content begins at line {1}: \n\n{2}\n\n'
                         'Problematic block within content: \n\n{TAB}{3}\n\n')
                    e = e.format(source, linenumber, content, block, TAB=TAB)

                    # Write, rather than include in exception, since Sphinx
                    # will truncate tracebacks.
                    sys.stdout.write(e)
                    raise RuntimeError('An invalid block was detected.')

                out_data = \
                    self.process_output(data, output_prompt, input_lines,
                                        output, is_doctest, decorator,
                                        image_file)
                if out_data:
                    # Then there was user submitted output in verbatim mode.
                    # We need to remove the last element of `ret` that was
                    # added in `process_input`, as it is '' and would introduce
                    # an undesirable newline.
                    assert(ret[-1] == '')
                    del ret[-1]

            if out_data:
                ret.extend(out_data)

        # save the image files
        if image_file is not None:
            self.save_image(image_file)

        return ret, image_directive
1366358
def call(commands, *, print_result=False, raise_exception=False,
         print_commands=False):
    
    if isinstance(commands, str):
        commands = commands.split()

    if not (isinstance(commands, tuple) or
            isinstance(commands, list)):
        raise ValueError("Function 'call' does not accept a 'commands'"
                         "argument of type '{}'".format(type(commands)))

    if raise_exception:
        print_result = False
    try:
        process = subprocess.Popen(commands,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        if print_commands:
            _print_commands(commands)

    except:
        # TODO Why couldn't we just do 'except Exception as output'
        output = traceback.format_exc()
        result = Result(1, stderr=output)
        if print_result and not raise_exception:
            print(output, file=sys.stderr)

    else:
        result = _extract_output(process, print_result, raise_exception)

    if raise_exception and (result.returncode == 1):
        message = "An error occurred in an external process:\n\n{}"
        raise Exception(message.format(result.getStderr()))
    return result
619052
def print_row(value, num_blocks, val_min, color):
    
    if color:
        sys.stdout.write(f'\033[{color}m') # Start to write colorized.

    if num_blocks < 1 and (value > val_min or value > 0):
        # Print something if it's not the smallest
        # and the normal value is less than one.
        sys.stdout.write(SM_TICK)
    else:
        for _ in range(num_blocks):
            sys.stdout.write(TICK)

    if color:
        sys.stdout.write('\033[0m')