tags:

views:

19

answers:

2

I use the following code to run "ls -l ./" and get the result in scratch buffer.

(start-process "my-process" "*scratch*" "ls" "-l" "./")
  • How can I get the result in clipboard or something (kill ring or whatever) so that I can easily copy the result whenever necessary?
+1  A: 

shell-command (bound to M-!) runs a shell command and puts its output in *Shell Command Output*. Given an argument (eg: M-1 M-!) it will put the results in the current buffer.

A little more information is available on the page ExecuteExternalCommand on the Emacs wiki

Bryan Oakley
Whereupon it is immediately kill-able. So `C-u M-! (command) RET C-w` gets the results into the kill ring. And you can use the minibuffer's history (`C-p` or up arrow) to easily re-enter recent commands without re-typing them.
phils
+1  A: 

You can adjust this to your liking:

(kill-new (shell-command-to-string "ls -l ."))

The call to kill-new will put the string from shell-command-to-string on the kill ring.

Trey Jackson