reddit / emacs

Create process and pipe buffer to process as input

Tohiko · 2022-04-27 14:49
When using the functions `make-process` or `start-process`, is there a way to pipe the content of a buffer as input to the created process? I need this especially for temporary buffers that do not have a file (I know that I can create a temporary file, but I would like to avoid this if possible). I couldn't find a way to do so. Even in eshell, when I try something like `cmd < #<buffer>` I get `Eshell does not support input redirection`.
h-m-b-tu · 2022-04-27 14:54
You can pass `make-process` the option `:connection-type 'pipe` and then use `process-send-string` to pass input to the process. Use `process-send-eof` to close the pipe.
rpluim · 2022-04-27 15:45
Does it have to use `make-process` or `start-process`? Because there's `shell-command-on-region` or the underlying `call-process-region`
globalcandyamnesia · 2022-04-27 16:30
(call-process-region (point-min) (point-max) "cat" nil t)
Tohiko · 2022-04-27 16:36
Brilliant!
Tohiko · 2022-04-27 16:37
These two functions create synchronous process as far as I can see, right? I need my process to be asynchronous.
nanounanue · 2022-04-28 02:44
Emacslisp noob here, mind to share the full code?
h-m-b-tu · 2022-04-28 09:19
Here as an example: ``` elisp (let ((process (make-process :name "process name" :buffer nil ;; no buffer for process output :command (list "executable" "argument_1" "argument_2" "..." "argument_n") :connection-type 'pipe))) (process-send-string process "string to pipe to process") (process-send-eof process) ;; close pipe ) ``` See also the documentation of `make-process`.