help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sending commands to shell with emacs lisp


From: Bruno Barbier
Subject: Re: sending commands to shell with emacs lisp
Date: 13 Sep 2009 07:45:36 GMT
User-agent: slrn/0.9.9p1 (Linux)

On 2009-09-13, tomas@tuxteam.de <tomas@tuxteam.de> wrote:
>
> On Sun, Sep 13, 2009 at 01:15:38AM -0400, Corey Foote wrote:
>> 
>> I'm trying to send commands to a shell buffer. I'm able to send the
>> command "hello world" by calling this:
>> 
>> (defun exec-command ()
>>   (interactive)
>>   (set-buffer (get-buffer "*shell*"))
>>   (insert "hello world"))
>> 
>> But I can't figure out how to send over the "enter key" to actually
>> make it execute the shell command. I'm an emacs lisp newbie!

I'm using the following code to send a command to an existing shell:

    (with-current-buffer buffer
      (let ((process (get-buffer-process (current-buffer)))
            )
        (unless process
          (error "No process in %s" buffer-or-name))
        (goto-char (process-mark process))
        (insert command-string)
        (comint-send-input nil 
                           t  ;; artificial
                           )
        ))

so, the magic is:
    (comint-send-input nil t)

When I'm not using a shell and I just want the shell command result,
I'm doing:

   (with-output-to-temp-buffer "*shell result*"
      (shell-command "echo hello world" "*shell result*")
      )



reply via email to

[Prev in Thread] Current Thread [Next in Thread]