Using emacs to control command-line processes

3

1

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:\my\directory\my.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.

User1

Posted 2009-10-27T14:40:30.440

Reputation: 7 653

Answers

3

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.

Doug Harris

Posted 2009-10-27T14:40:30.440

Reputation: 23 578

Can you expand on "run multiple shells within emacs"? That's the part I can't quite get to happen. A M-! gives a Shell Command Output buffer. Can I get several of these buffers? – User1 – 2009-10-27T15:12:07.360

I've updated the second bullet point to expand on your question. – Doug Harris – 2009-10-27T15:27:56.723

very nice! Bonus question: what's the best way to change the default path? – User1 – 2009-10-27T16:03:15.543

cmd.exe runs fine. Cygwin is grumpy. I'll open a new question. – User1 – 2009-10-27T19:16:35.560

A related question: http://superuser.com/questions/61605/running-cygwin-inferior-shell-in-emacs

– User1 – 2009-10-27T19:55:06.370