def get_subprocess_output(command, log, raise_on_empty_output=True):
 max_size = (1024 * 1024)
 with tempfile.SpooledTemporaryFile(max_size=max_size) as stdout_f:
  with tempfile.SpooledTemporaryFile(max_size=max_size) as stderr_f:
   proc = subprocess.Popen(command, stdout=stdout_f, stderr=stderr_f)
   proc.wait()
   stderr_f.seek(0)
   err = stderr_f.read()
   if err:
    log.debug('Error while running {0} : {1}'.format(' '.join(command), err))
   stdout_f.seek(0)
   output = stdout_f.read()
 if ((not output) and raise_on_empty_output):
  raise SubprocessOutputEmptyError('get_subprocess_output expected output but had none.')
 return (output, err, proc.returncode)

def get_subprocess_output ( command , log , raise_on_empty_output = True ) : max_size = ( 1024 * 1024 ) with tempfile . SpooledTemporaryFile ( max_size = max_size ) as stdout_f : with tempfile . SpooledTemporaryFile ( max_size = max_size ) as stderr_f : proc = subprocess . Popen ( command , stdout = stdout_f , stderr = stderr_f ) proc . wait ( ) stderr_f . seek ( 0 ) err = stderr_f . read ( ) if err : log . debug ( 'Error while running {0} : {1}' . format ( ' ' . join ( command ) , err ) ) stdout_f . seek ( 0 ) output = stdout_f . read ( ) if ( ( not output ) and raise_on_empty_output ) : raise SubprocessOutputEmptyError ( 'get_subprocess_output expected output but had none.' ) return ( output , err , proc . returncode )
run the given subprocess command and return its output .