2013-05-16 23:03:00 +02:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Command:
|
|
|
|
|
def __init__(self, command):
|
|
|
|
|
self.command = command
|
|
|
|
|
self.output = ""
|
|
|
|
|
self.error = ""
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
2013-05-27 03:54:04 +02:00
|
|
|
return self.command
|
2013-05-16 23:03:00 +02:00
|
|
|
|
|
|
|
|
def hasProcessed(self):
|
|
|
|
|
return self.output != "" and self.error != ""
|
|
|
|
|
|
|
|
|
|
def doProcess(self):
|
|
|
|
|
process = subprocess.Popen([self.command], stdout=subprocess.PIPE)
|
|
|
|
|
self.output, self.error = process.communicate()
|
|
|
|
|
|
|
|
|
|
def getOutput(self):
|
|
|
|
|
if not self.hasProcessed():
|
|
|
|
|
self.doProcess()
|
|
|
|
|
return self.output
|
|
|
|
|
|
|
|
|
|
def getError(self):
|
|
|
|
|
if not self.hasProcessed():
|
|
|
|
|
self.doProcess()
|
2013-05-27 03:54:04 +02:00
|
|
|
return self.error
|