Send command to terminal from emacs
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")
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)))
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")
)
E.x.:
(es-send-via-tmux "echo hello")
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 Terminal.app. Something like:
tell application "Terminal"
do script "ls"
end tell