@verbose
def run_subprocess(command, verbose=None, *args, **kwargs):
 for (stdxxx, sys_stdxxx) in (['stderr', sys.stderr], ['stdout', sys.stdout]):
  if (stdxxx not in kwargs):
   kwargs[stdxxx] = subprocess.PIPE
  elif (kwargs[stdxxx] is sys_stdxxx):
   if isinstance(sys_stdxxx, StringIO):
    kwargs[stdxxx] = subprocess.PIPE
   else:
    kwargs[stdxxx] = sys_stdxxx
 env = kwargs.get('env', os.environ)
 if any((p.startswith('~') for p in env['PATH'].split(os.pathsep))):
  warn('Your PATH environment variable contains at least one path starting with a tilde ("~") character. Such paths are not interpreted correctly from within Python. It is recommended that you use "$HOME" instead of "~".')
 if isinstance(command, string_types):
  command_str = command
 else:
  command_str = ' '.join(command)
 logger.info(('Running subprocess: %s' % command_str))
 try:
  p = subprocess.Popen(command, *args, **kwargs)
 except Exception:
  if isinstance(command, string_types):
   command_name = command.split()[0]
  else:
   command_name = command[0]
  logger.error(('Command not found: %s' % command_name))
  raise
 (stdout_, stderr) = p.communicate()
 stdout_ = ('' if (stdout_ is None) else stdout_.decode('utf-8'))
 stderr = ('' if (stderr is None) else stderr.decode('utf-8'))
 if stdout_.strip():
  logger.info(('stdout:\n%s' % stdout_))
 if stderr.strip():
  logger.info(('stderr:\n%s' % stderr))
 output = (stdout_, stderr)
 if p.returncode:
  print(output)
  err_fun = subprocess.CalledProcessError.__init__
  if ('output' in _get_args(err_fun)):
   raise subprocess.CalledProcessError(p.returncode, command, output)
  else:
   raise subprocess.CalledProcessError(p.returncode, command)
 return output

@ verbose def run_subprocess ( command , verbose = None , * args , ** kwargs ) : for ( stdxxx , sys_stdxxx ) in ( [ 'stderr' , sys . stderr ] , [ 'stdout' , sys . stdout ] ) : if ( stdxxx not in kwargs ) : kwargs [ stdxxx ] = subprocess . PIPE elif ( kwargs [ stdxxx ] is sys_stdxxx ) : if isinstance ( sys_stdxxx , StringIO ) : kwargs [ stdxxx ] = subprocess . PIPE else : kwargs [ stdxxx ] = sys_stdxxx env = kwargs . get ( 'env' , os . environ ) if any ( ( p . startswith ( '~' ) for p in env [ 'PATH' ] . split ( os . pathsep ) ) ) : warn ( 'Your PATH environment variable contains at least one path starting with a tilde ("~") character. Such paths are not interpreted correctly from within Python. It is recommended that you use "$HOME" instead of "~".' ) if isinstance ( command , string_types ) : command_str = command else : command_str = ' ' . join ( command ) logger . info ( ( 'Running subprocess: %s' % command_str ) ) try : p = subprocess . Popen ( command , * args , ** kwargs ) except Exception : if isinstance ( command , string_types ) : command_name = command . split ( ) [ 0 ] else : command_name = command [ 0 ] logger . error ( ( 'Command not found: %s' % command_name ) ) raise ( stdout_ , stderr ) = p . communicate ( ) stdout_ = ( '' if ( stdout_ is None ) else stdout_ . decode ( 'utf-8' ) ) stderr = ( '' if ( stderr is None ) else stderr . decode ( 'utf-8' ) ) if stdout_ . strip ( ) : logger . info ( ( 'stdout:\n%s' % stdout_ ) ) if stderr . strip ( ) : logger . info ( ( 'stderr:\n%s' % stderr ) ) output = ( stdout_ , stderr ) if p . returncode : print ( output ) err_fun = subprocess . CalledProcessError . __init__ if ( 'output' in _get_args ( err_fun ) ) : raise subprocess . CalledProcessError ( p . returncode , command , output ) else : raise subprocess . CalledProcessError ( p . returncode , command ) return output
run command using subprocess .