Commit 632d6037 authored by Florian Fischer's avatar Florian Fischer
Browse files

capture coordinator output

parent 7fce7052
......@@ -124,7 +124,10 @@ def run_remote_clients(cmd: str, out: Path, err: Path, csv: Path,
files = []
# Start coordinator
coordinator = Coordinator(len(hosts))
c_out = out.parent / f'coordinator-{out.name}'
c_err = err.parent / f'coordinator-{err.name}'
coordinator = Coordinator(len(hosts), out_file=c_out, err_file=c_err)
cmd += f' --coordinator {HOSTNAME}'
for host in hosts:
......
......@@ -12,12 +12,19 @@ COORDINATOR_EXE = f'{EMPER_CLIENT_DIR}/build/apps/coordinator'
class Coordinator(subprocess.Popen):
"""Coordniator class usable in a with statement"""
def __init__(self, nclients):
def __init__(self, nclients, out_file=None, err_file=None):
self.fout = subprocess.DEVNULL
self.ferr = subprocess.DEVNULL
if out_file:
self.fout = open(out_file, 'w')
if err_file:
self.ferr = open(err_file, 'w')
cmd = f'{COORDINATOR_EXE} {nclients}'
log.debug('Creating coordinator object with cmd: %s', cmd)
super().__init__(cmd.split(),
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
stdout=self.fout,
stderr=self.ferr)
def __enter__(self):
log.debug('Start coordinator')
......@@ -26,3 +33,9 @@ class Coordinator(subprocess.Popen):
def __exit__(self, exc_type, value, traceback): # pylint: disable=arguments-differ
log.debug('Join coordinator')
super().__exit__(exc_type, value, traceback)
def __del__(self):
if self.fout != subprocess.DEVNULL:
self.fout.close()
if self.ferr != subprocess.DEVNULL:
self.ferr.close()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment