我有以下代码来运行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
我不需要最后一部分,因为它不是来自python。有没有办法不得到这个字符串或有效地删除这个字符串?
Trey帮助我得到答案。
(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)
答案 0 :(得分:3)
你试过吗
(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")))