Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of "exec" in emacs *eshell*?

I want to write an eshell function that sort of wraps an existing command-line script. In order to do this, I want to be able to execute a shell command from an eshell function. My first instinct was to do something like

(defn eshell/myfunc ()
  (shell-command "mycommand"))

And this sort of works, except for a few problems. It runs in an inferior shell instead of behaving like a real "exec" command. This means that, among other things, the command "myfunc" in eshell appears to block while the command is running. The output of "mycommand" is collected an appears in a Shell Output buffer at the end, but it doesn't replicate the behavior of a normal shell function, where the standard output appears while it runs.

So, what's the correct way to do this?

like image 464
Derek Thurn Avatar asked Nov 04 '22 03:11

Derek Thurn


1 Answers

Try

(start-process-shell-command "foo" (current-buffer) "mycommand")

If you need more control, see Emacs Lisp Referece Manual, Sectioin 37.4 Creating an Asynchronous Process.

like image 68
huaiyuan Avatar answered Nov 09 '22 07:11

huaiyuan