1 import subprocess as sp
2 from subprocess import Popen
3 from subprocess import CalledProcessError
4 from datetime import datetime as dt
5
8 self.command = command
9 self.log = log
10 self.output = None
11 self.error = None
12 self.retcode = 0
13 self.commandStart = 0
14
17
19
20
21
22
23
24
25
26 try:
27 self.commandStart = dt.now()
28 self.log.i("calling command " + str(self.command) + " at " + str(self.commandStart))
29
30 process = Popen(self.command, stdout=sp.PIPE, stderr=sp.PIPE, shell=True)
31 self.output, self.error = process.communicate()
32 self.log.d(str(self.output))
33 self.log.d(str(self.error))
34 self.retcode = process.poll()
35 except CalledProcessError:
36 self.error = CalledProcessError.output
37 self.retcode = CalledProcessError.returncode
38
41
44
46 return str(self.output) + str(self.error) + str(self.retcode)
47
50