Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix stderr stdout output handling for remote connections #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions robmuxinator/robmuxinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,22 +180,24 @@ def send_cmd(self, cmd, wait_for_exit_status=True, get_pty=False):
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],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
text=True)
stdout = process.stdout
stderr = process.stderr

if wait_for_exit_status:
stdout_str, stderr_str = process.communicate()
# wrap output in IO buffers so it is compatible with .readlines()
stdout = io.StringIO(stdout_str)
stderr = io.StringIO(stderr_str)
stdout, stderr = process.communicate()
returncode = process.returncode
Deleh marked this conversation as resolved.
Show resolved Hide resolved
else:
stdout = process.stdout.read()
stderr = process.stderr.read()

logger.debug(
"send_cmd: {} took {} secs".format(
cmd, (datetime.now() - start).total_seconds()
Expand Down Expand Up @@ -235,13 +237,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:
Expand Down Expand Up @@ -533,8 +533,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)
Expand Down