如何从eLisp调用env并正确转义目标程序的路径? [英] How to invoke env from eLisp and escape the path to the target program properly?
问题描述
我想要做的是如下:
(let((pj-path(concat src haxe-项目生成器)))
(当(file-exist-p pj-path)
(shell-command
(concatenv(haxe-build-env-vars&参数>)
(格式'%s'pj-path)))))
即我想在一些变量环境中调用程序 pj-path
。
在行(格式'%s'pj-path)
我尝试单引号和双引号 - 但 env
不进行扩展如果它被引用,它会将其视为一个字符串,而不是找到该文件。但是,如果没有引用,那么它会解释字符串的一部分,直到第一个空格为程序路径。
如果我逃避空格(如前面的斜杠那样),这似乎是有效的,但是肯定的是,空格并不是唯一会混淆shell执行命令。
那么,逃避可以传递给eLisp中的env的可执行文件的名称的正确方法是什么?
$ b $($ shell-command(concatls
(shell-quote-argument/ path with spaces /(and parens)/)))
What I'm trying to do is as follows:
(let ((pj-path (concat src haxe-project-generator)))
(when (file-exists-p pj-path)
(shell-command
(concat "env " (haxe-build-env-vars <more arguments>)
(format "'%s'" pj-path)))))
I.e. I want to call a program pj-path
in environment populated with some variables.
In the line (format "'%s'" pj-path)
I tried single and double quotes - but env
doesn't do path expansion and if it is quoted, it will treat it as a string, not finding the file. However, if it is not quoted, then it will interpret the part of the string until the first white space as a path to program.
If I escape spaces (as in preceding them with backwards slash), it seems to work, but, surely, white spaces aren't the only character that would confuse the shell executing the command.
So, what is the proper way to escape the name of the executable which should be passed to env in eLisp?
Try shell-quote-argument
.
(shell-command (concat "ls "
(shell-quote-argument "/path with spaces/(and parens)/")))
这篇关于如何从eLisp调用env并正确转义目标程序的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!