diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-03-20 11:16:15 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-03-20 11:16:15 -0400 |
commit | 04b66bb955a456c951b024fe7b1545442fa32c5c (patch) | |
tree | 83a78ae517576708589cba28639a45e1cdddbc00 /cmd2/cmd2.py | |
parent | e42065ea805c813790ae91dd00e3677ed811c8cd (diff) | |
download | cmd2-git-04b66bb955a456c951b024fe7b1545442fa32c5c.tar.gz |
Simiplified code
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index c33e2927..d6eb121e 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -2941,19 +2941,15 @@ class Cmd(cmd.Cmd): expanded_command = ' '.join(tokens) - # For any output that is a StdSim, we will use a pipe so we can save the output - is_out_sim = isinstance(self.stdout, utils.StdSim) - is_err_sim = isinstance(sys.stderr, utils.StdSim) - - proc_stdout = subprocess.PIPE if is_out_sim else self.stdout - proc_stderr = subprocess.PIPE if is_err_sim else sys.stderr - - proc = subprocess.Popen(expanded_command, stdout=proc_stdout, stderr=proc_stderr, shell=True) - if is_out_sim or is_err_sim: - proc_reader = utils.ProcReader(proc, self.stdout, sys.stderr) - proc_reader.wait() - else: - proc.communicate() + # For any stream that is a StdSim, we will use a pipe so we can capture its output + proc = subprocess.Popen(expanded_command, + stdout=subprocess.PIPE if isinstance(self.stdout, utils.StdSim) else self.stdout, + stderr=subprocess.PIPE if isinstance(sys.stderr, utils.StdSim) else sys.stderr, + shell=True) + + # Use a ProcReader in all cases since the process will run normally even if no output is being captured + proc_reader = utils.ProcReader(proc, self.stdout, sys.stderr) + proc_reader.wait() @staticmethod def _reset_py_display() -> None: |