def _create_result(cmd, params):
    p = subprocess.Popen(cmd,
                         shell=True,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE,
                         env=os.environ)

    result = Result()

    for line in p.stdout.readlines():
        if sys.version_info[0] == 3:
            line = line.decode(sys.stdout.encoding)

        result._add_stdout_line(line)

    for line in p.stderr.readlines():
        if sys.version_info[0] == 3:
            line = line.decode(sys.stderr.encoding)

        result._add_stderr_line(line)

    p.wait()

    if (_is_param_set(params, _PARAM_PRINT_STDOUT) or config.PRINT_STDOUT_ALWAYS) and len(result.stdout) > 0:
        _print_stdout(result.stdout)

    if (_is_param_set(params, _PARAM_PRINT_STDERR) or config.PRINT_STDERR_ALWAYS) and len(result.stderr) > 0:
        if _is_colorama_enabled():
            _print_stderr(Fore.RED + result.stderr + Style.RESET_ALL)
        else:
            _print_stderr(result.stderr)

    result.returncode = p.returncode

    if p.returncode != 0 and not _is_param_set(params, _PARAM_NO_THROW):
        raise NonZeroReturnCodeError(cmd, result)

    return result
dataset/ETHPy150Open lamerman/shellpy/shellpython/core.py/_create_result/original