From 5daeb29fefffecc760492983ec79fd274ec36e35 Mon Sep 17 00:00:00 2001 From: pgehring Date: Mon, 14 Oct 2024 14:30:28 +0200 Subject: [PATCH] fix stderr stdout output handling for remote connections --- robmuxinator/robmuxinator.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/robmuxinator/robmuxinator.py b/robmuxinator/robmuxinator.py index e2c7fdf..5cba946 100755 --- a/robmuxinator/robmuxinator.py +++ b/robmuxinator/robmuxinator.py @@ -177,9 +177,13 @@ def send_cmd(self, cmd, wait_for_exit_status=True, get_pty=False): if not self._use_local_connection: self.init_connection() stdin, stdout, stderr = self.ssh_cli.exec_command(cmd, get_pty=get_pty) + logger.debug(f"{cmd}") if wait_for_exit_status: returncode = stdout.channel.recv_exit_status() + + stdout = stdout.read().decode() + stderr = stderr.read().decode() else: logger.debug(" using local connection") process = subprocess.Popen([cmd], @@ -187,8 +191,8 @@ def send_cmd(self, cmd, wait_for_exit_status=True, get_pty=False): stderr=subprocess.PIPE, shell=True, text=True) - stdout = process.stdout - stderr = process.stderr + stdout = process.stdout.read() + stderr = process.stderr.read() if wait_for_exit_status: stdout_str, stderr_str = process.communicate() @@ -235,13 +239,11 @@ def stop_session(self, session_name): pid_session = None if not returncode: - pid_session = stdout.readlines() - pid_session = pid_session[0].rstrip("\n") if len(pid_session) > 0 else None + pid_session = stdout[0].rstrip("\n") if len(stdout) > 0 else None if pid_session: cmd = "pgrep -P {}".format(pid_session) returncode, stdout, stderr = self.send_cmd(cmd) - pid = stdout.readlines() - pid = pid[0].rstrip("\n") if len(pid) > 0 else None + pid = stdout[0].rstrip("\n") if len(stdout) > 0 else None if not pid: logger.error(f" session {session_name}: could not get process pid for session pid") else: @@ -533,8 +535,8 @@ def start(self): ) logger.debug("pre_condition: {}".format(self._pre_condition)) logger.debug("ret: {}".format(ret)) - logger.debug("stdout: {}".format(stdout.getvalue())) - logger.debug("stderr: {}".format(stderr.getvalue())) + logger.debug("stdout: {}".format(stdout)) + logger.debug("stderr: {}".format(stderr)) if not ret: break time.sleep(0.25)