问题
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?
回答1:
Try shell-quote-argument
.
(shell-command (concat "ls "
(shell-quote-argument "/path with spaces/(and parens)/")))
来源:https://stackoverflow.com/questions/11189439/how-to-invoke-env-from-elisp-and-escape-the-path-to-the-target-program-properly