-1

I know about shell-command-on-region.

Is there any way to pipe a region through a non-shell command? The start-process and call-process functions invoke executables directly, without using the shell. I'd like to avoid shell overhead when piping the contents of a region into an external command, as well.

Can this be done in emacs?

Thanks in advance.

  • Please do not cross-post the same question to SO and emacs.SE. Choose one or the other. Thx. – Drew Dec 3 '16 at 0:12
  • 1
    What overhead do you perceive? What platform are you using? shell-command-on-region ends up calling call-process-region with the variable shell-file-name as the command. – icarus Dec 3 '16 at 0:16
  • Yes, I know that the shell-file-name program is used to invoke the command. If I invoke call-process with "/usr/bin/wc", the shell (for example, perhaps /bin/sh) is invoked, and then it goes ahead and calls /usr/bin/wc. The "overhead" I'm talking about is the invocation of /bin/sh. I want to be able to pipe directly into /usr/bin/wc from the buffer, without /bin/sh also being called. It appears that this is not possible in emacs, but perhaps I'm missing something. – HippoMan Dec 5 '16 at 15:11
  • I stumbled upon make-pipe-process. I think i can use it to create a process for running an executable without using any shell, which can then accept input via send-process. That input could be the contents of a buffer. I will code up a proof-of-concept, and if it works, I'll post it here as an answer. Excelsior! – HippoMan Dec 6 '16 at 1:05
1

I figured it out. It turns out that I can send input to a process invoked via start-process, and so I don't need to use call-process at all. Since start-process doesn't invoke the specified command via the shell, this solves my problem.

Here is a simplified example which shows how to do it ...

(let ((proc (start-process "procname" "buffname" "/path/to/executable" "arg0" "arg1")))
  (process-send-region proc (point-min) (point-max))
  (process-send-eof proc))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.