Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

which shell-command in emacs lisp?

Tags:

emacs

elisp

If I am trying to run a shell-command in an Emacs Lisp function in which I call rsync (or scp) multiple times, which shell-command variant should I use? I am currently using shell-command, which locks up Emacs until the process is done, and the output that should be visible with the --verbose to rsync is not printed; I can use shell-command with an & at the end of the command string to make it asynchronous, which does print the progress — but while it doesn't "lock up" Emacs entirely, the minibuffer repeatedly asks if I want to kill the process which is crippling in the meantime; and start-process-shell-command, which appears to halt the function only after the first file/directory is transferred; neglecting the rest when there are multiple rsync calls made through my function. None of these seem ideal, any hints?

like image 369
hatmatrix Avatar asked Sep 21 '09 10:09

hatmatrix


2 Answers

I have had the most success using start-process myself.

(start-process "process-name" 
               (get-buffer-create "*rsync-buffer*") 
               "/path/to/rsync"
               arg1
               ...
               argn)

This will send all the output to a single buffer.

like image 150
Jonathan Arkell Avatar answered Nov 15 '22 23:11

Jonathan Arkell


One solution might be to run the command in an actual shell buffer. Then you get to choose which one of those to run:

M-x shell
M-x eshell
M-x term

If you like that idea, you can code it up like this:

(defun my-rsync-routine ()
  "run some rsync processes"
  (with-temp-buffer
    (shell (current-buffer))
    (process-send-string nil "rsync ...")
    (process-send-string nil "rsync ...")
    (process-send-string nil "rsync ...")))

Read more on 'process-send-string for its usage. You might also want to have some error checking on the output from the processes.

like image 31
Trey Jackson Avatar answered Nov 15 '22 22:11

Trey Jackson