Problem with emacs lisp shell process arguments

I am trying to run P4V commands directly from xemacs. After I put p4.el in emacs, I wrote the following:

(defun p4v-command (cmd) (get-buffer-create p4-output-buffer-name);; We do these two lines (kill-buffer p4-output-buffer-name) ;; to ensure no duplicates (call-process "p4v" nil (get-buffer-create p4-output-buffer-name) nil "-p" (p4-get-p4-port) "-u" "UserName" "-c" (p4-current-client) "-cmd" (shell-quote-argument (concat cmd " " (buffer-name)))) (display-buffer p4-output-buffer-name)) 

I am trying to get the following for a shell command (when cmd is equal to prevdiff):

 p4v -p port -u user -c client -cmd "prevdiff file.txt" 

However, when I execute the above function with prevdiff, I get the following error

 P4V: unrecognized argument '"prevdiff' for '-cmd' option. 

Thus, it seems that the call process breaks the quoted line "prevdiff file.txt" into separate arguments, and P4V processes only the first.

This is not like the other commands I tried with call processing, so I'm not sure if this is a lisp problem or something related to P4V.

Does anyone know how to solve this?

+4
source share
1 answer

call-process definitely does not combine its arguments; he passes them directly to the program. To verify this, enter M-: and evaluate the following expression:

 (call-process "/bin/ls" nil "*scratch*" nil "avg ba") 

where "avg" and "ba" are the files in the current directory. I get the following message inserted into my zero buffer:

 /bin/ls: cannot access avg ba: No such file or directory 

If the invocation process reanalyzed the arguments, it would split "avg ba" into two separate arguments --- but the error message indicates that it is not.

Instead, the problem is with the shell-quote argument. When I evaluate the call that you mention in the buffer from scratch, I get the following:

 (shell-quote-argument "prevdiff file.txt") "prevdiff\\ file.txt" 

In other words, the p4v command actually gets what you would enter into the shell, like:

 p4v -p port -u user -c client -cmd '"prevdiff file.txt"' 

This is why p4v complains about "prevdiff".

So, I think what you want, namely:

 "-cmd" (concat cmd " " (shell-quote-argument (buffer-name)))) 

(but of course check my parens).

+4
source

All Articles