我有以下代码来运行 python 并在 scratch 缓冲区中获取结果。
(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)
Python代码如下。
if __name__ == "__main__":
print "hello, world from Python"
使用 C-c k 在 scratch 缓冲区中提供以下代码。
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)
最佳答案
你试过吗
(shell-command-to-string "/Users/smcho/Desktop/temp/hello.py")
这将返回一个字符串,您可以将其插入到 scratch 缓冲区中,如下所示:
(with-current-buffer "*scratch*"
(insert (shell-command-to-string "/Users/smcho/Desktop/temp/hello.py")))
关于emacs - 过滤在 emacs/elisp 中运行启动进程的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3569461/