Filtering result from running start-process in emacs/elisp

孤街浪徒 提交于 2019-12-11 01:39:10

问题


I have the following code to run python and get the result in scratch buffer.

(defun hello ()
  "Test, just prints Hello, world to mini buffer"
  (interactive)
  (start-process "my-process" "*scratch*" "python" "/Users/smcho/Desktop/temp/hello.py")
  (message "Hello, world : I'm glad to see you"))
(define-key global-map "\C-ck" 'hello)

The python code is as follows.

if __name__ == "__main__":
    print "hello, world from Python"

Using C-c k gives me the following code in scratch buffer.

hello, world from Python

Process my-process finished

I don't need the last part, as it's not from the python. Is there a way not to get this string or deleting this one effectively?

Added

Trey helped me to get an answer.

(defun hello ()
  "Test, just prints Hello, world to mini buffer"
 (interactive)
  (insert (shell-command-to-string "python /Users/smcho/Desktop/temp/hello.py"))
 (message "Hello, world : I'm glad to see you"))
(define-key global-map "\C-ck" 'hello)

回答1:


Have you tried

(shell-command-to-string "/Users/smcho/Desktop/temp/hello.py")

That will return a string that you can insert in the scratch buffer like so:

(with-current-buffer "*scratch*"
  (insert (shell-command-to-string "/Users/smcho/Desktop/temp/hello.py")))


来源:https://stackoverflow.com/questions/3569461/filtering-result-from-running-start-process-in-emacs-elisp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!