linspector-old/lib/core/command.py

40 lines
1 KiB
Python
Raw Normal View History

import subprocess as sp
from subprocess import CalledProcessError
from datetime import datetime as dt
2013-05-16 23:03:00 +02:00
class Command:
def __init__(self, command):
self.command = command
self.output = ""
self.error = ""
self.retcode = 0
self.commandStart=0
2013-05-16 23:03:00 +02:00
def __str__(self):
2013-05-27 03:54:04 +02:00
return self.command
2013-05-16 23:03:00 +02:00
def call(self):
'''
self.commandStart = dt.now()
"called at: "
process = sp.Popen(stdout=PIPE, *popenargs, **kwargs)
2013-05-16 23:03:00 +02:00
self.output, self.error = process.communicate()
self.retcode = process.poll()
'''
try:
print self.command
self.output=sp.check_output(self.command.split(),stderr=sp.STDOUT)
except CalledProcessError:
self.error=CalledProcessError.output
self.retcode = CalledProcessError.returncode
2013-05-16 23:03:00 +02:00
def getOutput(self):
return self.output
def getError(self):
return self.error
def getReturnCode(self):
return self.retcode