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 self.commandStart = dt.now()
21 "called at: "
22 process = sp.Popen(stdout=PIPE, *popenargs, **kwargs)
23 self.output, self.error = process.communicate()
24 self.retcode = process.poll()
25 '''
26 try:
27 self.commandStart = dt.now()
28 self.log.d("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
39
42
45
47 return str(self.output) + str(self.error) + str(self.retcode)
48
51