Skip to content

Commit 2beb3de

Browse files
committed
The pipe process in redirection now writes its output to self.stdout so we can capture it
1 parent f93d51b commit 2beb3de

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

cmd2/cmd2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,21 +1902,21 @@ def _redirect_output(self, statement: Statement) -> RedirectionSavedState:
19021902
read_fd, write_fd = os.pipe()
19031903

19041904
# Open each side of the pipe and set stdout accordingly
1905-
subproc_stdin = io.open(read_fd, 'r')
1906-
new_stdout = io.open(write_fd, 'w')
1905+
pipe_read = io.open(read_fd, 'r')
1906+
pipe_write = io.open(write_fd, 'w')
19071907

19081908
# We want Popen to raise an exception if it fails to open the process. Thus we don't set shell to True.
19091909
try:
1910-
pipe_proc = subprocess.Popen(statement.pipe_to, stdin=subproc_stdin)
1910+
pipe_proc = subprocess.Popen(statement.pipe_to, stdin=pipe_read, stdout=self.stdout)
19111911
ret_val = RedirectionSavedState(self_stdout=self.stdout,
19121912
sys_stdout=None,
19131913
pipe_proc=self.pipe_proc)
1914-
self.stdout = new_stdout
1914+
self.stdout = pipe_write
19151915
self.pipe_proc = pipe_proc
19161916
except Exception as ex:
19171917
self.perror('Not piping because - {}'.format(ex), traceback_war=False)
1918-
subproc_stdin.close()
1919-
new_stdout.close()
1918+
pipe_read.close()
1919+
pipe_write.close()
19201920

19211921
elif statement.output:
19221922
import tempfile

0 commit comments

Comments
 (0)