Ejemplo n.º 1
0
def run_logged(cmd):
    """Run command and get the return value."""
    ctx.logger.info(_('Running %s') % " ".join(cmd))
    if ctx.stdout:
        stdout = ctx.stdout
    else:
        if ctx.get_option('debug'):
            stdout = None
        else:
            stdout = subprocess.PIPE
    if ctx.stderr:
        stderr = ctx.stderr
    else:
        if ctx.get_option('debug'):
            stderr = None
        else:
            stderr = subprocess.STDOUT

    p = subprocess.Popen(cmd, shell=True, stdout=stdout, stderr=stderr)
    out, err = p.communicate()
    ctx.logger.debug(_('return value for "%s" is %s') % (" ".join(cmd), p.returncode))

    return p.returncode