Function: shell-eval-command
shell-eval-command is a byte-compiled function defined in shell.el.gz.
Signature
(shell-eval-command COMMAND)
Documentation
Eval COMMAND in the current shell process and return the result.
Source Code
;; Defined in /usr/src/emacs/lisp/shell.el.gz
(defun shell-eval-command (command)
"Eval COMMAND in the current shell process and return the result."
(let* ((proc (get-buffer-process (current-buffer)))
(old-filter (process-filter proc))
(result "")
prev)
(unwind-protect
(progn
(set-process-filter
proc
(lambda (_proc string)
(setq result (concat result string))))
(process-send-string proc command)
;; Wait until we get a prompt (which will be a line without
;; a newline). This is far from fool-proof -- if something
;; outputs incomplete data and then sleeps, we'll think
;; we've received the prompt.
(while (not (let* ((lines (string-lines result nil t))
(last (car (last lines)))
(last-end (if (equal last "")
last
(substring last -1))))
(and (length> lines 0)
(not (member last '("" "\n")))
(not (equal last-end "\n"))
(or (not prev)
(not (equal last prev)))
(setq prev last))))
(accept-process-output proc 0 100)))
;; Restore old filter.
(set-process-filter proc old-filter))
;; Remove the prompt.
(replace-regexp-in-string "\n.*\\'" "\n" result)))