tags:

views:

31

answers:

1

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)
+2  A: 

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")))
Trey Jackson
@Trey : I run the code, and the result seems to go to minibuffer, not to the current buffer or anything.
prosseek
@prosseek Not sure what you're wanting here. The above returns a string. You can have it put in the current buffer by wrapping it with `(insert (shell-command....))`. Generally one doesn't program emacs-lisp by dumping strings into the *scratch* buffer and working on them...
Trey Jackson