diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-03-19 02:32:53 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-03-19 02:32:53 -0400 |
commit | 2beb3debc4dd9501b9578d3a2c4c61f679b4d50c (patch) | |
tree | 01920a2bbfe525673c54a34a2e9cb72201f84b73 /cmd2/cmd2.py | |
parent | f93d51ba6921b1d7a33fdaab6eb5b1748969e3eb (diff) | |
download | cmd2-git-2beb3debc4dd9501b9578d3a2c4c61f679b4d50c.tar.gz |
The pipe process in redirection now writes its output to self.stdout so we can capture it
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 22a35da4..389db391 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -1902,21 +1902,21 @@ class Cmd(cmd.Cmd): read_fd, write_fd = os.pipe() # Open each side of the pipe and set stdout accordingly - subproc_stdin = io.open(read_fd, 'r') - new_stdout = io.open(write_fd, 'w') + pipe_read = io.open(read_fd, 'r') + pipe_write = io.open(write_fd, 'w') # We want Popen to raise an exception if it fails to open the process. Thus we don't set shell to True. try: - pipe_proc = subprocess.Popen(statement.pipe_to, stdin=subproc_stdin) + pipe_proc = subprocess.Popen(statement.pipe_to, stdin=pipe_read, stdout=self.stdout) ret_val = RedirectionSavedState(self_stdout=self.stdout, sys_stdout=None, pipe_proc=self.pipe_proc) - self.stdout = new_stdout + self.stdout = pipe_write self.pipe_proc = pipe_proc except Exception as ex: self.perror('Not piping because - {}'.format(ex), traceback_war=False) - subproc_stdin.close() - new_stdout.close() + pipe_read.close() + pipe_write.close() elif statement.output: import tempfile |