summaryrefslogtreecommitdiffstats
path: root/ms/command-executor/src/main/python/command_executor_handler.py
diff options
context:
space:
mode:
Diffstat (limited to 'ms/command-executor/src/main/python/command_executor_handler.py')
-rw-r--r--ms/command-executor/src/main/python/command_executor_handler.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/ms/command-executor/src/main/python/command_executor_handler.py b/ms/command-executor/src/main/python/command_executor_handler.py
index a5951fdb3..365c00188 100644
--- a/ms/command-executor/src/main/python/command_executor_handler.py
+++ b/ms/command-executor/src/main/python/command_executor_handler.py
@@ -19,6 +19,7 @@ from subprocess import CalledProcessError, PIPE
import logging
import os
import subprocess
+import sys
import virtualenv
import venv
import utils
@@ -37,10 +38,7 @@ class CommandExecutorHandler():
self.installed = self.venv_home + '/.installed'
def is_installed(self):
- if os.path.exists(self.installed):
- return True
- else:
- return False
+ return os.path.exists(self.installed)
def prepare_env(self, request, results):
if not self.is_installed():
@@ -78,7 +76,16 @@ class CommandExecutorHandler():
self.logger.info("Command: {}".format(cmd))
try:
- results.append(os.popen(cmd).read())
+ with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+ shell=True, bufsize=1, universal_newlines=True) as newProcess:
+ while True:
+ output = newProcess.stdout.readline()
+ if output == '' and newProcess.poll() is not None:
+ break
+ if output:
+ self.logger.info(output.strip())
+ results.append(output.strip())
+ rc = newProcess.poll()
except Exception as e:
self.logger.info("{} - Failed to execute command. Error: {}".format(self.blueprint_id, e))
results.append(e)