Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to run a command in a running iterm tab (or terminal, whatever) from elisp. I don't want to use a terminal emulator running under emacs, since I've yet to find one that handles output as well as a standalone terminal emulator.

Is this possible?

I basically need this, but for a process that isn't running under emacs:

(term-simple-send proc "echo hello")
share|improve this question
Have you tried M-x term? This one seems to work quite like a real terminal. – cYrus Jul 6 '12 at 17:03
I use ansi-term right now, and it works ok but not nearly as well as Terminal or iTerm. The buffer scrolls slower on output, sometimes gets "stuck" where the last output line isn't at the bottom of the buffer, I haven't figured out how to get it to use a different smaller font, C-x b occasionally puts me in the test buffer accidentally, trouble with unicode. I'd just like to use a native terminal if it's a possible thing. – spike Jul 6 '12 at 17:29
I think what both the op and I are looking for is something like this: (I used this before i switched from Vim... there has to be an emacs way of doing this?) – joefromct Jul 21 '15 at 20:16
@joefromct check out my self-answer below. – spike Jul 21 '15 at 20:38
up vote 2 down vote accepted

If you are really just concerned about output quality, why not call uxterm with the -hold option as so?

(defun external-xterm-shell-command (COMMAND)
  "Run a terminal command in an external xterm window."
  (interactive "sShell Command: ")
  (shell-command (concat "uxterm -hold -e " COMMAND)))
share|improve this answer
The running tab part is critical for me. I'm using this for automated testing and i want an always visible terminal that keeps getting reused, and doesn't steal focus when I run a test. Can you send a command to a running uxterm instance? I'd prefer iterm or (not firing up X11) but don't really care so much about that point. – spike Jul 7 '12 at 14:34
I'm not aware of anyway to do this, sorry. Why aren't you just appending output to a file? Emacs is pretty good at displaying those ;) – wdkrnls Jul 7 '12 at 15:57
That's not a bad idea actually, I could just tail -f the file in an open terminal. I'd probably lose color codes, but nice thought. (would upvote you but I have no rep on superuser) Going to leave the question open in case someone else comes along. – spike Jul 7 '12 at 17:26

Been some time since I used OS X. IIRC, you can use the osascript utility to run AppleScript which could be used to send a command to Something like:

tell application "Terminal"
  do script "ls"
end tell
share|improve this answer
I like this idea, but can't find a way to call a running terminal tab. everything I do opens a new one (I can run multiple commands in that new terminal, but only within the same tell ... end block) – spike Jul 11 '12 at 13:01
When I used this Terminal didn't have tabs; it used to run the command in the active window. Maybe… contains some hint. – Ankur Jul 12 '12 at 8:39

I've found a solution that seems to be working nicely.

Using tmux, I can send a command to a running session like this:

(defun es-send-via-tmux (command)
  (message (concat "running: " command))
  (call-process "/usr/local/bin/tmux" nil nil nil "send-keys" "-t 1" command "C-m")


(es-send-via-tmux "echo hello") 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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