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