当前位置: 首页>>代码示例>>Python>>正文


Python CalledProcessError.result方法代码示例

本文整理汇总了Python中subprocess.CalledProcessError.result方法的典型用法代码示例。如果您正苦于以下问题:Python CalledProcessError.result方法的具体用法?Python CalledProcessError.result怎么用?Python CalledProcessError.result使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在subprocess.CalledProcessError的用法示例。


在下文中一共展示了CalledProcessError.result方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: capture_subprocess

# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import result [as 别名]
def capture_subprocess(cmd, encoding='UTF-8', **popen_kwargs):
    """Run a command, showing its usual outputs in real time,
    and return its stdout, stderr output as strings.

    No temporary files are used.
    """
    stdout = Pty()  # libc uses full buffering for stdout if it doesn't see a tty
    stderr = Pipe()

    # deadlocks occur if we have any write-end of a pipe open more than once
    # best practice: close any used write pipes just after spawn
    outputter = Popen(
        cmd,
        stdout=stdout.write,
        stderr=stderr.write,
        **popen_kwargs
    )
    stdout.readonly()  # deadlock otherwise
    stderr.readonly()  # deadlock otherwise

    # start one tee each on the original stdout and stderr
    # writing each to three places:
    #    1. the original destination
    #    2. a pipe just for that one stream
    stdout_tee = Tee(stdout.read, STDOUT)
    stderr_tee = Tee(stderr.read, STDERR)

    # clean up left-over processes and pipes:
    exit_code = outputter.wait()
    result = (stdout_tee.join(), stderr_tee.join())

    if encoding is not None:
        result = tuple(
            bytestring.decode(encoding)
            for bytestring in result
        )

    if exit_code == 0:
        return result
    else:
        error = CalledProcessError(exit_code, cmd)
        error.result = result
        raise error
开发者ID:ENuge,项目名称:pip-faster,代码行数:45,代码来源:capture_subprocess.py


注:本文中的subprocess.CalledProcessError.result方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。