aboutsummaryrefslogtreecommitdiffstats
path: root/utils/functest_utils.py
diff options
context:
space:
mode:
authorjose.lausuch <jose.lausuch@ericsson.com>2016-09-02 08:06:28 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-09-02 08:06:28 +0000
commitd77f374bf43b95e4b367fc8559d8801f4b429e19 (patch)
treeac41ff5b3192db173bed2446400cb00f49290da3 /utils/functest_utils.py
parent1112c54ad5487350cc3593b60bb9a859a1267f67 (diff)
parent75479a40514ef2cea93d2ef032e5bfe00f987714 (diff)
Merge "Add print-to-a-file option when executing a command in functest_utils"
Diffstat (limited to 'utils/functest_utils.py')
-rw-r--r--utils/functest_utils.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/utils/functest_utils.py b/utils/functest_utils.py
index 8c5dd835..644ad1a1 100644
--- a/utils/functest_utils.py
+++ b/utils/functest_utils.py
@@ -294,7 +294,7 @@ def get_ci_envvars():
def execute_command(cmd, exit_on_error=True, info=False, error_msg="",
- verbose=True):
+ verbose=True, output_file=None):
if not error_msg:
error_msg = ("The command '%s' failed." % cmd)
msg_exec = ("Executing command: '%s'" % cmd)
@@ -305,10 +305,17 @@ def execute_command(cmd, exit_on_error=True, info=False, error_msg="",
logger.debug(msg_exec)
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
+ if output_file:
+ f = open(output_file, "w")
for line in iter(p.stdout.readline, b''):
- line = line.replace('\n', '')
- print line
- sys.stdout.flush()
+ if output_file:
+ f.write(line)
+ else:
+ line = line.replace('\n', '')
+ print line
+ sys.stdout.flush()
+ if output_file:
+ f.close()
p.stdout.close()
returncode = p.wait()
if returncode != 0: