diff options
author | Alex Tomlins <alex@tomlins.org.uk> | 2019-01-22 20:40:05 +0000 |
---|---|---|
committer | Brian May <brian@linuxpenguins.xyz> | 2019-01-23 18:53:45 +1300 |
commit | 04849df7e37adb983cc360b1cc6ef27c14229f56 (patch) | |
tree | 910afa3820a8663ab35c61cbf9326ddb4011c116 | |
parent | 531a17c151aefd817158946c48aa1eec8dcf7994 (diff) |
Use subprocess.check_output instead of run
subprocess.run only exists for python3, and this needs to also support
python 2.7
-rw-r--r-- | sshuttle/linux.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/sshuttle/linux.py b/sshuttle/linux.py index 5251ab3..f2704a3 100644 --- a/sshuttle/linux.py +++ b/sshuttle/linux.py @@ -24,12 +24,13 @@ def ipt_chain_exists(family, table, name): 'PATH': os.environ['PATH'], 'LC_ALL': "C", } - completed = ssubprocess.run(argv, stdout=ssubprocess.PIPE, env=env, encoding='ASCII') - if completed.returncode: - raise Fatal('%r returned %d' % (argv, completed.returncode)) - for line in completed.stdout.split('\n'): - if line.startswith('Chain %s ' % name): - return True + try: + output = ssubprocess.check_output(argv, env=env) + for line in output.decode('ASCII').split('\n'): + if line.startswith('Chain %s ' % name): + return True + except ssubprocess.CalledProcessError as e: + raise Fatal('%r returned %d' % (argv, e.returncode)) def ipt(family, table, *args): |