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


Python CalledProcessError.output方法代码示例

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


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

示例1: check_media_file

# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import output [as 别名]
 def check_media_file(self, filename):
     valid_media_msg = '%s => OK' % filename
     invalid_media_msg = '%s => INVALID' % filename
     try:
         # cmd = self.validate_cmd.format(filename)
         cmd = self.validate_cmd
         log.debug('cmd: %s %s', cmd, filename)
         log.info('verifying {0}'.format(filename))
         # capturing stderr to stdout because ffprobe prints to stderr in all cases
         # Python 2.7+
         #subprocess.check_output(cmd.split() + [filename], stderr=subprocess.STDOUT)
         proc = subprocess.Popen(cmd.split() + [filename], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
         (stdout, _) = proc.communicate()
         returncode = proc.wait()
         if returncode != 0 or (stdout is not None and 'Error' in stdout):
             _ = CalledProcessError(returncode, cmd)
             _.output = stdout
             raise _
         print(valid_media_msg)
     except CalledProcessError as _:
         if self.verbose > 2:
             print(_.output)
         if self.skip_errors:
             print(invalid_media_msg)
             self.failed = True
             return False
         die(invalid_media_msg)
开发者ID:minc-yang,项目名称:pytools,代码行数:29,代码来源:validate_multimedia.py

示例2: check_output

# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import output [as 别名]
def check_output(*popenargs, **kwargs):
    r"""Run command with arguments and return its output as a byte string.

    If the exit code was non-zero it raises a CalledProcessError.  The
    CalledProcessError object will have the return code in the returncode
    attribute and output in the output attribute.

    The arguments are the same as for the Popen constructor.  Example:

    >>> check_output(["ls", "-l", "/dev/null"])
    'crw-rw-rw- 1 root root 1, 3 Oct 18  2007 /dev/null\n'

    The stdout argument is not allowed as it is used internally.
    To capture standard error in the result, use stderr=STDOUT.

    >>> check_output(["/bin/sh", "-c",
    ...               "ls -l non_existent_file ; exit 0"],
    ...              stderr=STDOUT)
    'ls: non_existent_file: No such file or directory\n'
    """
    from subprocess import PIPE, CalledProcessError, Popen
    if 'stdout' in kwargs:
        raise ValueError('stdout argument not allowed, it will be overridden.')
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
    output, unused_err = process.communicate()
    retcode = process.poll()
    if retcode:
        cmd = kwargs.get("args")
        if cmd is None:
            cmd = popenargs[0]
        err = CalledProcessError(retcode, cmd)
        err.output = output
        raise err
    return output
开发者ID:caseyg,项目名称:cooperdiffs,代码行数:36,代码来源:scraper.py

示例3: log_check_call

# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import output [as 别名]
def log_check_call(*args, **kwargs):
    kwargs['record_output'] = True
    retcode, output = log_call(*args, **kwargs)
    if retcode != 0:
        cmd = kwargs.get('args')
        if cmd is None:
            cmd = args[0]
        e = CalledProcessError(retcode, cmd)
        e.output = output
        raise e
    return 0
开发者ID:pigsoldierlu,项目名称:sheep,代码行数:13,代码来源:util.py

示例4: check_output

# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import output [as 别名]
 def check_output(*args, **kwds):
     process = Popen(stdout=PIPE, *args, **kwds)
     output, _ = process.communicate()
     retcode = process.poll()
     if retcode:
         cmd = kwds.get("args")
         if cmd is None:
             cmd = args[0]
         error = CalledProcessError(retcode, cmd)
         error.output = output
         raise error
     return output
开发者ID:GennadyKharlam,项目名称:igraph,代码行数:14,代码来源:create-msvc-projectfile.py

示例5: check_output

# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import output [as 别名]
def check_output(*popenargs, **kwargs):
    """Run command with arguments and return its output as a byte string."""
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
    output, unused_err = process.communicate()
    retcode = process.poll()
    if retcode:
        cmd = kwargs.get("args")
        if cmd is None:
            cmd = popenargs[0]
        error = CalledProcessError(retcode, cmd)
        error.output = output
        raise error
    return output
开发者ID:OpenXT-Extras,项目名称:build-machines,代码行数:15,代码来源:prepare_scratch.py

示例6: mockreturn

# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import output [as 别名]
 def mockreturn(*args, **kwargs):
     if args == (['task', 'stats'],):
         output = b"""
         Category Data
         -------- ----
         Pending 0
         Waiting 0"""
         return output
     elif args == (['task', 'overdue'],):
         output = b'No matches.'
         e = CalledProcessError(1, 'task')
         e.output = output
         raise e
开发者ID:tablet-mode,项目名称:py3status-modules,代码行数:15,代码来源:test_taskstatus.py

示例7: call_for_stderr

# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import output [as 别名]
def call_for_stderr(command, *args, **kwargs):
    kwargs["stderr"] = _subprocess.PIPE

    proc = start_process(command, *args, **kwargs)
    output = proc.communicate()[1].decode("utf-8")
    exit_code = proc.poll()

    if exit_code != 0:
        error = CalledProcessError(exit_code, proc.command_string)
        error.output = output

        raise error

    return output
开发者ID:ssorj,项目名称:quiver,代码行数:16,代码来源:plano.py

示例8: __run

# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import output [as 别名]
 def __run(self, *args, **kwargs):
     _args = [i for i in args if i is not None]
     argsLog = [self.__hidePassw(i) for i in args if i is not None ]
     logging.debug("CMD: " + " ". join(argsLog))
     process = Popen(
         _args, stdout=kwargs.pop('stdout', PIPE),
         stderr=kwargs.pop('stderr', PIPE),
         close_fds=kwargs.pop('close_fds', True), **kwargs)
     stdout, stderr = process.communicate()
     if process.returncode:
         exception = CalledProcessError(
             process.returncode, repr(args))
         exception.output = ''.join(filter(None, [stdout, stderr]))
         raise Error('1001', err=exception.output)
     return stdout
开发者ID:atodor,项目名称:HPCC-Platform,代码行数:17,代码来源:shell.py

示例9: check_output

# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import output [as 别名]
    def check_output(arguments, stdin=None, stderr=None, shell=False):
        temp_f = mkstemp()
        returncode = call(arguments, stdin=stdin, stdout=temp_f[0], stderr=stderr, shell=shell)
        close(temp_f[0])
        file_o = open(temp_f[1], 'r')
        cmd_output = file_o.read()
        file_o.close()
        remove(temp_f[1])

        if returncode != 0:
            error_cmd = CalledProcessError(returncode, arguments[0])
            error_cmd.output = cmd_output
            raise error_cmd
        else:
            return cmd_output
开发者ID:wazuh,项目名称:ossec-wazuh,代码行数:17,代码来源:oscap.py

示例10: __run

# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import output [as 别名]
 def __run(self, *args, **kwargs):
     _args = [i for i in args if i is not None]
     argsLog = [self.__hidePassw(i) for i in args if i is not None]
     logging.debug("Shell _run CMD: " + " ".join(argsLog))
     process = Popen(_args, stdout=PIPE, stderr=PIPE, close_fds=True, **kwargs)
     stdout, stderr = process.communicate()
     retCode = process.returncode
     logging.debug("Shell _run retCode: %d", retCode)
     logging.debug("            stdout:'%s'", stdout)
     logging.debug("            stderr:'%s'", stderr)
     if retCode or ((len(stderr) > 0) and ("Error" in stderr)):
         exception = CalledProcessError(process.returncode, repr(args))
         exception.output = "".join(filter(None, [stdout, stderr]))
         logging.debug("exception.output:'%s'", exception.output)
         raise Error("1001", err=repr(exception.output))
     return stdout
开发者ID:kereno,项目名称:HPCC-Platform,代码行数:18,代码来源:shell.py

示例11: check_output

# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import output [as 别名]
def check_output(*args, **kwargs):

    if 'stdout' in kwargs:
        raise ValueError('stdout argument not allowed, it will be overridden.')
    process = subprocess.Popen(stdout=subprocess.PIPE, *args, **kwargs)
    output, unused_err = process.communicate()
    retcode = process.poll()
    if retcode:
        cmd = kwargs.get("args")
        if cmd is None:
            cmd = args[0]

        error = CalledProcessError(retcode, cmd)
        error.output = output
        raise error

    return output
开发者ID:protomouse,项目名称:protostream,代码行数:19,代码来源:process.py

示例12: call_for_output

# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import output [as 别名]
def call_for_output(command, *args, **kwargs):
    kwargs["stdout"] = _subprocess.PIPE

    proc = start_process(command, *args, **kwargs)
    output = proc.communicate()[0]
    exit_code = proc.poll()

    if exit_code not in (None, 0):
        command_string = _command_string(command)
        command_string = command_string.format(*args)

        error = CalledProcessError(exit_code, command_string)
        error.output = output

        raise error

    return output
开发者ID:jdanekrh,项目名称:blinky,代码行数:19,代码来源:plano.py

示例13: execute_php_export

# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import output [as 别名]
def execute_php_export(command, articleid):
    print "PHP Exporting article {0}:\n\t`$ {1}\n`".format(articleid, command)
    args = command.split()
    process = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
    pout, perr = process.communicate()
    code = process.poll()
    if code or pout or perr:
        output = pout + perr
        try:
            raise CalledProcessError(
                code, command, output=output
            )
        except Exception:
            error = CalledProcessError(code, command)
            error.output = output
            raise error
    print "PHP export of article {0} complete\n".format(articleid)
    return code
开发者ID:cewing,项目名称:rcr_export_control,代码行数:20,代码来源:utils.py

示例14: log_check_call

# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import output [as 别名]
def log_check_call(*args, **kwargs):
    log = kwargs.pop('log', logging.debug)
    kwargs['stdout'] = PIPE
    kwargs['stderr'] = STDOUT
    kwargs['env'] = env = kwargs.get('env', os.environ.copy())
    env['PYTHONUNBUFFERED'] = '1'
    p = Popen(*args, **kwargs)
    output = []
    for line in iter(p.stdout.readline, ''):
        log(line.rstrip())
        output.append(line)
    retcode = p.wait()
    if retcode != 0:
        cmd = kwargs.get('args') or args[0]
        e = CalledProcessError(retcode, cmd)
        e.output = ''.join(output)
        raise e
    return 0
开发者ID:pigsoldierlu,项目名称:sheep,代码行数:20,代码来源:install.py

示例15: _check_output

# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import output [as 别名]
def _check_output(*popenargs, **kwargs):
    # Copyright (c) 2003-2005 by Peter Astrand <[email protected]>
    #
    # Licensed to PSF under a Contributor Agreement.
    # See http://www.python.org/2.4/license for licensing details.
    if 'stdout' in kwargs:
        raise ValueError('stdout argument not allowed, it will be overridden.')
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
    output, _ = process.communicate()
    retcode = process.poll()
    if retcode:
        cmd = kwargs.get("args")
        if cmd is None:
            cmd = popenargs[0]
        e = CalledProcessError(retcode, cmd)
        e.output = output
        raise e
    return output
开发者ID:timbutler,项目名称:python-agent,代码行数:20,代码来源:utils.py


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