elisp - Emacs call-process as sudo -


update

i have accepted @sean answer, small modifications.

(defun sudo-shell-command (buffer password command)   (let ((proc (start-process-shell-command            "*sudo*"            buffer            (concat "sudo bash -c "                    (shell-quote-argument command)))))     ;;; added @sean answer display passed buffer     (display-buffer buffer '((display-buffer . nil)) nil)     (process-send-string proc password)     (process-send-string proc "\r")     (process-send-eof proc)))  (defun sudo-bundle-install (password)   (interactive (list (read-passwd "sudo password bundle install: ")))   (let ((default-directory (concat default-directory                                "./fixtures/test-kitchen-mode-test-run/"))     ;;; added accepted answer below @sean     ;;; need buffer display process in.     (generated-buffer (generate-new-buffer "*test-kitchen-test-setup*")))     (sudo-shell-command       ;;; pass reference generated process buffer name.       ;;; need add defun current test-kitchen buffer        ;;; if exists use, outside scope of question.       (buffer-name generated-buffer)       password       "bundle install; bundle exec berks install")     (clear-string password))) 

say need call process in elisp, , process requires sudo priveleges. example, running ruby's bundle install:

(let ((generated-buffer (generate-new-buffer "*test-kitchen-test-setup*")))   (display-buffer generated-buffer '((display-buffer . nil)) nil)   (call-process-shell-command     (concat "cd " (concat default-directory "./fixtures/test-kitchen-mode-test-run")              "; sudo bundle install; sudo bundle exec berks install;")     nil generated-buffer t)) 

the bundle command requires sudo install gems correctly. how can call shell command in elisp sudo, enter password, , still able display results in generated window?

here's helper function executes single shell command sudo supplied password:

(defun sudo-shell-command (buffer password command)   (let ((proc (start-process-shell-command                "*sudo*"                buffer                (concat "sudo bash -c "                        (shell-quote-argument command)))))     (process-send-string proc password)     (process-send-string proc "\r")     (process-send-eof proc))) 

you might apply situation so:

(defun sudo-bundle-install (password)   (interactive (list (read-passwd "sudo password bundle install: ")))   (let ((default-directory (concat default-directory                                    "./fixtures/test-kitchen-mode-test-run/")))     (sudo-shell-command      "*test-kitchen-test-setup*"      password      "bundle install; bundle exec berks install")     (clear-string password))) 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -