Using emacs to control command-line processes

Posted on


I have a large amount of command-line utilities that I use in day-to-day development (eg Maven, ant, Grizzly, mplayer, CASE tools, etc). I use Windows. Every time I want to kick off a new process, I end up having to create a new cmd.exe process and type in what I want to run. Sometimes, I’ll have five cmd.exe’s open at a time!! It’s getting hard to manage.

Is there some way to do this directly in emacs? Here’s what I would like:

  • Have several cmd.exe’s output be stored in emacs (probably a new buffer for each)
  • Ability to send stdin and ctrl-c to the process
  • Easy way to restart the command without retyping the whole thing (like pressing the up arrow in cmd.exe)
  • Ability to paste certain parameters to the command to run (eg -file=C:mydirectorymy.file)
  • Ability to copy output to the clipboard. Ideally not breaking at 40 columns or so like cmd.exe does.

This sounds like a workable task in emacs, but I can’t quite figure out how to do it. I’d love to be able to use ssh and do something similar on remote Linux boxes as well.

Maybe there’s another more obvious solution than emacs. If so, please enlighten me.

EDIT: I noticed emacs has a eshell command. I think my needs would be met if I could get this to work on several buffers at once.


I’m a linux/emacs biased person, so here’s what I would try:

  • install cygwin with its version of emacs
  • run multiple shells within emacs. M-x shell launches a shell within emacs. If you give a prefix arg (C-u M-x shell), emacs will prompt you for the name to give to the shell buffer. This way you can have multiple shell buffers.
  • create bash aliases for the various tasks to run, for example create an alias called “mp” for something like “mplayer -option1 -option2 23

Many people who aren’t linux/cygwin inclined like PowerShell. This also provides aliases. Some people have written about running powershell inside emacs.

Leave a Reply

Your email address will not be published. Required fields are marked *