1 import subprocess 2 3 4 -class Command: 5 - def __init__(self, command): 6 self.command = command 7 self.output = "" 8 self.error = "" 9 10 - def __str__(self): 11 return self.command 12 13 - def hasProcessed(self): 14 return self.output != "" and self.error != "" 15 16 - def doProcess(self): 17 process = subprocess.Popen([self.command], stdout=subprocess.PIPE) 18 self.output, self.error = process.communicate() 19 20 - def getOutput(self): 21 if not self.hasProcessed(): 22 self.doProcess() 23 return self.output 24 25 - def getError(self): 26 if not self.hasProcessed(): 27 self.doProcess() 28 return self.error 29