emacs:如何从dired-do-shell-command捕获stdout?

时间:2015-04-22 21:33:17

标签: emacs dired

在Emacs中,有没有办法捕获dired-do-shell命令的stdout,比如杀死环?

在不知道如何操作的情况下,我最终转到 Messages 缓冲区并从那里手动获取stdout。

1 个答案:

答案 0 :(得分:1)

该命令的帮助说输出转到名为*Shell Command Output*的缓冲区,假设命令没有&。如果是这种情况,这段代码将按您的要求执行:

(defun do-shell-and-copy-to-kill-ring (command &optional arg file-list)
  (interactive
   (let ((files (dired-get-marked-files t current-prefix-arg)))
     (list
      (dired-read-shell-command "! on %s: " current-prefix-arg files)
      current-prefix-arg
      files)))
  (dired-do-shell-command command arg file-list)
  (with-current-buffer "*Shell Command Output*"
    (copy-region-as-kill (point-min) (point-max))))

对于异步命令,您需要等待它们并查看*Async Shell Command*缓冲区。