diff --git a/i3pystatus/core/command.py b/i3pystatus/core/command.py index 3a7813b..8303b4a 100644 --- a/i3pystatus/core/command.py +++ b/i3pystatus/core/command.py @@ -1,6 +1,9 @@ # from subprocess import CalledProcessError +from collections import namedtuple import subprocess +CommandResult = namedtuple("Result", ['rc', 'out', 'err']) + def run_through_shell(command, enable_shell=False): """ @@ -10,10 +13,11 @@ def run_through_shell(command, enable_shell=False): Don't use this function with programs that outputs lots of data since the output is saved in one variable """ + returncode = None + stderr = None try: proc = subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=enable_shell) - out, stderr = proc.communicate() out = out.decode("UTF-8") stderr = stderr.decode("UTF-8") @@ -26,4 +30,4 @@ def run_through_shell(command, enable_shell=False): except subprocess.CalledProcessError as e: out = e.output - return returncode, out, stderr + return CommandResult(returncode, out, stderr)