diff --git a/libtmux/common.py b/libtmux/common.py index cb6cfa405..103b1c61b 100644 --- a/libtmux/common.py +++ b/libtmux/common.py @@ -189,6 +189,7 @@ def __init__(self, *args, **kwargs): self.process.stdout.close() stderr = self.process.stderr.read() self.process.stderr.close() + returncode = self.process.returncode except Exception as e: logger.error( 'Exception for %s: \n%s' % ( @@ -197,6 +198,8 @@ def __init__(self, *args, **kwargs): ) ) + self.returncode = returncode + self.stdout = console_to_str(stdout) self.stdout = self.stdout.split('\n') self.stdout = list(filter(None, self.stdout)) # filter empty values diff --git a/libtmux/server.py b/libtmux/server.py index 7a1655933..74f06f25b 100644 --- a/libtmux/server.py +++ b/libtmux/server.py @@ -334,24 +334,11 @@ def has_session(self, target_session, exact=True): proc = self.cmd('has-session', '-t%s' % target_session) - if not proc.stdout: - return True - if any( - x in proc.stdout for x in - ['failed to connect to server', 'error connecting to'] - ): - return False - elif 'no server running' in proc.stdout: # tmux 2.0 - return False - elif 'can\'t find session' in proc.stdout: # tmux 2.1 - return False - elif 'bad session name' in proc.stdout: # tmux >= 1.9 - return False - elif 'session not found' in proc.stdout: - return False - else: + if not proc.returncode: return True + return False + def kill_server(self): """``$ tmux kill-server``.""" self.cmd('kill-server')