-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessRunner.py
31 lines (25 loc) · 894 Bytes
/
ProcessRunner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
__author__ = 'Mikhail K. Savkin'
from logging import getLogger
from subprocess import PIPE, Popen
class ProcessRunner:
def __init__(self, command, *args):
self.__log = getLogger(__name__)
self.__run(command, *args)
def __run(self, command, *args):
self.__log.debug(
"Running process '%s' with arguments (%s)",
command, ", ".join(args))
argsList = [command]
if len(args):
argsList += args
# We need shell=True to find *.bat files in PATH
process = Popen(argsList, stdout=PIPE, stderr=PIPE, shell=True)
result = process.communicate()
(outputData, errorData) = (data.rstrip() for data in result)
if len(outputData) > 0:
self.__log.debug("Process STDOUT: %s", outputData)
if len(errorData) > 0:
self.__log.debug("Process STDERR: %s", errorData)
result = process.returncode
if result:
raise RuntimeError("Not zero process return code: %d", result)