0

I'm something of an Emacs newbie. I would like to run a shell script I've written and insert the output into the buffer I'm working in. But the script requires some interaction, so ideally I'd like a workflow where I:

  • Call a command from the main buffer
  • Shell or Term mode opens, I interact with the script, the script gives final output and exits
  • Final output is inserted at the point in my main buffer

Is this feasible?

I've read some of the documentation on shell mode, the GNU documentation on running shell commands in Emacs and other material I've been able to find, but I can't find anything that addresses this issue specifically. I may have just missed it, of course.

ShankarG
  • 101
  • I do not know how to do what it is that you seek, but the function `shell-command-to-string` can be used to return a value and that can be modified as needed; e.g., by modifying the string. E.g., `(insert (car (split-string (shell-command-to-string "date") "\n")))`. To enter commands underneath the shell hood, there are the functions `comint-send-string` and `comint-send-input`, the latter of which is required if the former does not contain a `\n` at the end of the string. – lawlist Sep 23 '19 at 08:01
  • @lawlist but these commands don't allow for interaction with the shell, do they? – ShankarG Sep 23 '19 at 08:34
  • Here is a link to an example where the shell buffer output is copied to the kill-ring: https://emacs.stackexchange.com/questions/30458/how-to-send-shell-stdout-directly-to-kill-ring Perhaps you can take that example and modify it to your needs. If you do not need much interaction with the shell script, perhaps you could write your own function that looks for specific input from the user, and then continues to its conclusion where it finally inserts the output into your working buffer. You may also want to try Googling things like: **shell redirect output emacs** – lawlist Sep 23 '19 at 18:25

0 Answers0