How do I redirect output from a process to another buffer? reddit / emacs ---------------------------------------------------------------------- cuntymccuntlicker · 2022-07-04 01:38 I have a python interpreter running in one buffer, I want to send it some command, and have the output be placed into a different buffer, say "buf-out". For instance, if I sent ​ import time for i in range(10): time.sleep(0.5) print(i, end="\r") to my python interpreter, I would like to see in "buf-out" the sequence of numbers from 0 to 9 overwrite each other every half- second. Essentially, I want to see in "buf-out" exactly what I would see in the shell after pressing RET. Is there a way to do this? I tried with comint-redirect but it does not interpret the carriage return, and it also displays the ">>>" prompt that gets printed after the code finishes running. ---------------------------------------------------------------------- cuntymccuntlicker · 2022-07-04 04:29 Is there any way to modify comint-output-filter or something? ---------------------------------------------------------------------- ieure · 2022-07-04 16:08 (setq comint-redirect-output-buffer "*destination buffer*") (add-hook comint-preoutput-filter-functions #'comint-redirect- preoutput-filter) This is probably going to see everything that gets written, including the REPL prompt, so you may need to build your own function using `comint-redirect-preoutput-filter` and the `python-mode` stuff. ---------------------------------------------------------------------- 1nc0ns1st3nt · 2022-07-05 09:10 I would also recommend **alternatively** using `ob-python`, which is using source blocks in an org file, it is a style of literate programming, and the output will be saved in the same buffer, however, to redirect to another buffer, here are some tweaks that you can apply: [https://emacs.stackexchange.com/questions/23870/org-babel- result-to-a-separate- buffer](https://emacs.stackexchange.com/questions/23870/org-babel- result-to-a-separate-buffer)