(*popenargs, **kwargs)
return (stdout, stderr, retcode)
Function to call a subprocess and gather the output.
Function to call a subprocess and gather the output.
Function to call a subprocess and gather the output .
def subprocess_check_output(*popenargs, **kwargs):
    """
Function to call a subprocess and gather the output.
"""
    if 'stdout' in kwargs:
        raise ValueError('stdout argument not allowed, it will be overridden.')
    if 'stderr' in kwargs:
        raise ValueError('stderr argument not allowed, it will be overridden.')

    #executable_exists(popenargs[0][0])

    # NOTE: it is very, very important that we use temporary files for
    # collecting stdout and stderr here. There is a nasty bug in python
    # subprocess; if your process produces more than 64k of data on an fd that
    # is using subprocess.PIPE, the whole thing will hang. To avoid this, we
    # use temporary fds to capture the data
    stdouttmp = TemporaryFile()
    stderrtmp = TemporaryFile()

    process = subprocess.Popen(stdout=stdouttmp, stderr=stderrtmp, *popenargs,
                               **kwargs)
    process.communicate()
    retcode = process.poll()

    stdouttmp.seek(0, 0)
    stdout = stdouttmp.read()
    stdouttmp.close()

    stderrtmp.seek(0, 0)
    stderr = stderrtmp.read()
    stderrtmp.close()

    if retcode:
        cmd = ' '.join(*popenargs)
        raise Exception("'%s' failed(%d): %s" % (cmd, retcode, stderr), retcode)
    return (stdout, stderr, retcode)
def subprocess_check_output ( * popenargs , * * kwargs ) : if 'stdout' in kwargs : raise ValueError ( 'stdout argument not allowed, it will be overridden.' ) if 'stderr' in kwargs : raise ValueError ( 'stderr argument not allowed, it will be overridden.' ) #executable_exists(popenargs[0][0]) # NOTE: it is very, very important that we use temporary files for # collecting stdout and stderr here. There is a nasty bug in python # subprocess; if your process produces more than 64k of data on an fd that # is using subprocess.PIPE, the whole thing will hang. To avoid this, we # use temporary fds to capture the data stdouttmp = TemporaryFile ( ) stderrtmp = TemporaryFile ( ) process = subprocess . Popen ( stdout = stdouttmp , stderr = stderrtmp , * popenargs , * * kwargs ) process . communicate ( ) retcode = process . poll ( ) stdouttmp . seek ( 0 , 0 ) stdout = stdouttmp . read ( ) stdouttmp . close ( ) stderrtmp . seek ( 0 , 0 ) stderr = stderrtmp . read ( ) stderrtmp . close ( ) if retcode : cmd = ' ' . join ( * popenargs ) raise Exception ( "'%s' failed(%d): %s" % ( cmd , retcode , stderr ) , retcode ) return ( stdout , stderr , retcode )