Return decoded output from command.
541236
def backtick (cmd, encoding='utf-8'):
    """"""
    data = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
    return data.decode(encoding)
1012353
def decodebytes(input):
    """"""
    py_version = sys.version_info[0]
    if py_version >= 3:
        return _decodebytes_py3(input)
    return _decodebytes_py2(input)
110852
def postprocess_result(morphresult, trim_phonetic, trim_compound):
    """"""
    word, analysis = morphresult
    return {
        'text': deconvert(word),
        'analysis': [postprocess_analysis(a, trim_phonetic, trim_compound) for a in analysis]
    }
840422
def ainput(prompt='', *, streams=None, use_stderr=False, loop=None):
    """"""
    # Get standard streams
    if streams is None:
        streams = yield from get_standard_streams(
            use_stderr=use_stderr, loop=loop)
    reader, writer = streams
    # Write prompt
    writer.write(prompt.encode())
    yield from writer.drain()
    # Get data
    data = yield from reader.readline()
    # Decode data
    data = data.decode()
    # Return or raise EOF
    if not data.endswith('\n'):
        raise EOFError
    return data.rstrip('\n')
682236
def get_data(self, ptr, unbuffered=False):
        """"""
        result = _decode(self.get_raw_data(ptr, unbuffered),
                         self._reading_format[self.ws_type])
        return result
597512
def encode(cls, command):
        

        args = []
        for arg in command.args:
            if not isinstance(arg, str):
                arg = str(arg)

            if "," in arg or arg.startswith(" ") or arg.endswith(" ") or arg.startswith("hex:"):
                arg = "hex:{}".format(hexlify(arg.encode('utf-8')).decode('utf-8'))

            args.append(arg)

        argstr = ""

        if len(args) > 0:
            argstr = " {" + ",".join(args) + "}"

        return command.name + argstr
446781
def call_output(cmd, stdin=None, encoding_errors="replace", **kwargs):
    """"""
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
    stdout, stderr, retcode = [], [], None
    while retcode is None:
        if stdin is not None:
            logger.log_prefix("<0 ", stdin.rstrip())
        raw_out, raw_err = p.communicate(stdin)
        stdin = None

        out = raw_out.decode(get_encoding(sys.stdout), encoding_errors) if raw_out else ""
        if out:
            logger.log_prefix("1> ", out.rstrip())
        stdout.append(out)

        err = raw_err.decode(get_encoding(sys.stderr), encoding_errors) if raw_err else ""
        if err:
            logger.log_prefix("2> ", err.rstrip())
        stderr.append(err)

        retcode = p.poll()
    return stdout, stderr, retcode
165618
def wrap_output(output, encoding):
    """"""
    return codecs.getwriter(encoding)(output.buffer
                                      if hasattr(output, 'buffer')
                                      else output)
303928
def _output_to_list(cmdoutput):
    '''
    
    '''
    return [item for line in cmdoutput.splitlines() if _safe_output(line) for item in line.split()]
1000268
def readCmd(cls, cmd):
        
        args = shlex.split(cmd)
        proc = subprocess.Popen(args, stdout=subprocess.PIPE)
        (proc_stdout, proc_stderr) = proc.communicate(input=None)  # proc_stdin
        return proc_stdout.decode()
1083866
def get_external_command_output(command: str) -> bytes:
    
    args = shlex.split(command)
    ret = subprocess.check_output(args)  # this needs Python 2.7 or higher
    return ret
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')
539336
def call(cmd, input_file=None, input_text=None, encoding=None):
    """"""

    process = get_process(cmd)

    if input_file is not None:
        with open(input_file, 'rb') as f:
            process.stdin.write(f.read())
    if input_text is not None:
        process.stdin.write(input_text)

    return get_process_output(process, encoding)
1036870
def _ee_decode(self, msg):
        """"""
        return {'area': int(msg[4:5])-1, 'is_exit': msg[5:6] == '0',
                'timer1': int(msg[6:9]), 'timer2': int(msg[9:12]),
                'armed_status': msg[12:13]}
1085270
def command(self, command, raw=False, timeout_ms=None):
    """"""
    return ''.join(self.streaming_command(command, raw, timeout_ms))
288701
def get_lines(command):
    
    stdout = get_output(command)
    return [line.strip().decode('utf-8') for line in stdout.splitlines()]
352675
def _read_output(self, command):
        
        cmd = []
        cmd.extend(self._prefix)
        cmd.extend([self._path, "-iP"])
        cmd.extend(command)
        command = cmd

        logger.debug("Cmd %s" % command)
        null = open('/dev/null', 'w')
        process = subprocess.Popen(
            command, stdout=subprocess.PIPE, stderr=null)
        null.close()

        results = []
        reader = csv.reader(_input_csv(process.stdout), delimiter=str("|"))

        try:
            headers = next(reader)
            logger.debug("<-- headers %s" % headers)
        except StopIteration:
            logger.debug("Cmd %s headers not found" % command)
            headers = []

        for row in reader:
            _output_csv(row)

            logger.debug("<-- row %s" % row)
            this_row = {}

            i = 0
            for i in range(0, len(headers)):
                key = headers[i]
                value = row[i]
                this_row[key] = value

            results.append(this_row)

        process.stdout.close()
        retcode = process.wait()
        if retcode != 0:
            logger.error("<-- Cmd %s returned %d (error)" % (command, retcode))
            raise subprocess.CalledProcessError(retcode, command)

        if len(headers) == 0:
            logger.error("Cmd %s didn't return any headers." % command)
            raise RuntimeError("Cmd %s didn't return any headers." % command)

        logger.debug("<-- Returned: %d (good)" % retcode)
        return results