Running Asynchronous Processes in Eshell

Nacho Barrientos has an interesting video in which he explains how to run an eshell process in the background. Barrientos illustrates this with the sleep command. Normally, if you enter

sleep 4

in Eshell, Emacs will hang until sleep completes in 4 seconds. Barrientos’ idea is to use the Emacs compile mechanism to run the command in the background. The output is redirected to the *compile* buffer and the Eshell prompt returns immediately.

That’s a nice way of starting a long running process from Eshell and being able to continue working in Emacs. He also has a way of burying the *compile* buffer and getting a message when the process completes.

There’s not a lot of code needed to implement this. You can see the relevant function in Barrientos’ init.el. If you use Eshell regularly and sometimes want to invoke long-running processes, it’s worth taking a look at this video. The run time is only 4 minutes, 21 seconds so it should be easy to fit it in

UPDATE [2021-12-31 Fri 13:03]: In the comments, Niklas Eklund writes that he has a package that does the same sort of thing. You can read his post about it here. Elkund’s package works with any shell so it may be a worthwhile addition to your configuration.

This entry was posted in General and tagged . Bookmark the permalink.