diff options
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: |