+def getoutput(cmd):
+ sp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ output = None
+ output = sp.stdout.read()
+ if sys.version_info > (3,):
+ output = output.decode('utf-8') # TODO: is utf-8 okay here?
+ output = output.rstrip()
+ rval = sp.wait()
+ if rval:
+ # Failed!
+ print("Command '%s' failed with exit code %d." % (cmd, rval))
+ sys.exit(rval)
+ return output
+
+