From 5fe49fa9fa6b5c30cde01a34ed70cd67df096026 Mon Sep 17 00:00:00 2001 From: nojhan Date: Sun, 24 Jan 2010 21:52:36 +0000 Subject: [PATCH] replace popen3 with subprocess (need python >= 2.4) --- ereshkigal.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ereshkigal.py b/ereshkigal.py index 51a64c5..608749f 100644 --- a/ereshkigal.py +++ b/ereshkigal.py @@ -25,6 +25,7 @@ ################################################################################################# import os +import subprocess # fort sorting dictionaries easily from operator import itemgetter @@ -146,7 +147,13 @@ class AutoSSHTunnelMonitor(list): """Gather and parse autossh processes""" # call the command - status = os.popen3( self.ps_cmd ) + #status = os.popen3( self.ps_cmd ) + + p = subprocess.Popen( self.ps_cmd, shell=True, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) + + status = (p.stdin, p.stdout, p.stderr) + # list of processes with the "autossh" string status_list = [ps for ps in status[1].readlines() if "autossh" in ps] @@ -176,8 +183,13 @@ class AutoSSHTunnelMonitor(list): def get_connections(self): """Gather and parse ssh connections related to a tunnel""" - status = os.popen3( self.network_cmd ) - + #status = os.popen3( self.network_cmd ) + + p = subprocess.Popen( self.network_cmd, shell=True, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) + + status = (p.stdin, p.stdout, p.stderr) + status_list = status[1].readlines() list = [i.split() for i in status_list if 'ssh' in i]