[英]How to invoke env from eLisp and escape the path to the target program properly?
我想要做的是如下:
(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)))))
即我想在填充了一些變量的環境中調用程序pj-path
。
在行(format "'%s'" pj-path)
我嘗試了單引號和雙引號 - 但是env
不進行路徑擴展,如果引用它,它會將其視為字符串,而不是查找文件。 但是,如果沒有引用,那么它將解釋字符串的一部分,直到第一個空格作為編程路徑。
如果我逃避空間(就像在它們前面用向后的斜線),它似乎工作,但是,當然,白色空格不是唯一會混淆執行命令的shell的字符。
那么,在eLisp中傳遞應該傳遞給env的可執行文件名稱的正確方法是什么?
嘗試shell-quote-argument
。
(shell-command (concat "ls "
(shell-quote-argument "/path with spaces/(and parens)/")))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.