无法在elisp中将字符串作为shell命令执行

时间:2013-07-11 14:37:56

标签: shell emacs elisp

(shell-command "\"C:\\Documents and Settings\\ggustafson\\Desktop\\stuff\\ctags58\\ctags.exe\" -eR -f \"C:\\Documents and Settings\\ggustafson\\Desktop\\BlueTooth_7020\\TAGS\" \"C:\\Documents and Settings\\ggustafson\\Desktop\\BlueTooth_7020\"")

(message "\"C:\\Documents and Settings\\ggustafson\\Desktop\\stuff\\ctags58\\ctags.exe\" -eR -f \"C:\\Documents and Settings\\ggustafson\\Desktop\\BlueTooth_7020\\TAGS\" \"C:\\Documents and Settings\\ggustafson\\Desktop\\BlueTooth_7020\"")

执行顶层表单会给我错误'C:\Documents' is not recognized as an internal or external command, operable program or batch file.。执行输出第二个表单放入*Messages*缓冲区按预期工作(创建标记文件)。

为什么我不能用这两种技术获得相同的结果? shell-command在将字符串发送到shell之前是否会执行更改字符串的操作?我如何使用elisp执行字符串,就像我将其粘贴到命令提示符中一样?

shell-quote-argument不起作用,因为它产生的字符串无法用任何一种方法执行:

(message (shell-quote-argument "\"C:\\Documents and Settings\\ggustafson\\Desktop\\stuff\\ctags58\\ctags.exe\" -eR -f \"C:\\Documents and Settings\\ggustafson\\Desktop\\BlueTooth_7020\\TAGS\" \"C:\\Documents and Settings\\ggustafson\\Desktop\\BlueTooth_7020\""))
"^\"\\^\"C:\\Documents and Settings\\ggustafson\\Desktop\\stuff\\ctags58\\ctags.exe\\^\" -eR -f \\^\"C:\\Documents and Settings\\ggustafson\\Desktop\\BlueTooth_7020\\TAGS\\^\" \\^\"C:\\Documents and Settings\\ggustafson\\Desktop\\BlueTooth_7020\\^\"^\""

3 个答案:

答案 0 :(得分:2)

shell-quote-argument用于将单个参数引用到shell命令(因此名称),而不是完整的shell命令。

鉴于您所看到的错误表明某处缺少引用,使用内置命令处理引用而不是手动编写并假设您具有正确的语法似乎是个好主意。

另一种选择是使用 M - !以交互方式执行命令(或类似的命令),找出接受的内容,然后使用 Cx M - :获取elisp表格。

答案 1 :(得分:1)

如果执行使用相同的路径,我建议你重新检查两个,因此ctags.exe相同。我认为这可能是问题所在。您可能希望使用ctags.exe的完整路径来确保这一点。

如果我在普通shell上使用-Re选项,我的ctags(Linux)会给我同样的错误;这就是让我这么想的原因。

答案 2 :(得分:0)

我强烈建议你在这里使用call-program而不是shell-command,因为你没有使用shell的任何功能,它只会妨碍你,强迫你这样做引用体操向贝壳解释你的意思。