def RunShellWithReturnCode(command, print_output=False, universal_newlines=True, env=os.environ):
 logging.info('Running %s', command)
 p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=use_shell, universal_newlines=universal_newlines, env=env)
 if print_output:
  output_array = []
  while True:
   line = p.stdout.readline()
   if (not line):
    break
   print line.strip('\n')
   output_array.append(line)
  output = ''.join(output_array)
 else:
  output = p.stdout.read()
 p.wait()
 errout = p.stderr.read()
 if (print_output and errout):
  print >>sys.stderr, errout
 p.stdout.close()
 p.stderr.close()
 return (output, p.returncode)

def RunShellWithReturnCode ( command , print_output = False , universal_newlines = True , env = os . environ ) : logging . info ( 'Running %s' , command ) p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , shell = use_shell , universal_newlines = universal_newlines , env = env ) if print_output : output_array = [ ] while True : line = p . stdout . readline ( ) if ( not line ) : break print line . strip ( '\n' ) output_array . append ( line ) output = '' . join ( output_array ) else : output = p . stdout . read ( ) p . wait ( ) errout = p . stderr . read ( ) if ( print_output and errout ) : print >> sys . stderr , errout p . stdout . close ( ) p . stderr . close ( ) return ( output , p . returncode )
executes a command and returns the output from stdout and the return code .