一些Emacs的包(例如AUCTeX)由通過用戶指定的外殼命令到殼:將參數傳遞給呼叫處理上cmdproxy
(call-process shell-file-name nil 0 nil shell-command-switch the-user-specified-command)
其中在MS Windows中的情況下,通常是等效於:
(call-process "cmdproxy" nil 0 nil "-c" the-user-specified-command)
我應該如何逃脫字符,如果我想通過這個shell命令:
"print arg.py" "11 11" "22 22"
它運行以股代息t(帶有空格,其基名爲print arg.py
),其中有兩個參數11 11
和22 22
?
在下面的調用中,cmdproxy只是說Unable to initialize device PRN
。
(call-process "cmdproxy"
nil "foo" nil
"-c"
"\"print arg.py\" \"11 11\" \"22 22\"")
對於下面的調用,它說:error: no program name specified.
(call-process "cmdproxy"
nil "foo" nil
"-c"
"\"\"print arg.py\"\" \"\"11 11\"\" \"\"22 22\"\"")
對於下面的,它說:'\"print arg.py\"' is not recognized as an internal or external command, operable program or batch file.
(call-process "cmdproxy"
nil "foo" nil
"-c"
"\\\"print arg.py\\\" \\\"11 11\\\" \\\"22 22\\\"")
在另一方面,下面的調用運行的腳本成功參數11 11
和22 22
。
(setenv "ABC" "\"print arg.py\" \"11 11\" \"22 22\"")
(call-process "cmdproxy"
nil "foo" nil
"-c"
"%ABC%")
這可能是一個很好的解決方法,但它不能告訴如何轉義字符。
內容的腳本文件print arg.py
的,對於那些誰想要測試:
import sys
if __name__ == "__main__":
print "start"
for arg in sys.argv[1:]:
print "(" + arg + ")"
print "end"
需要修改包的代碼。該軟件包的用戶只能更改用戶選項the-user-specified-command或爲某種方式發出功能請求。 AUCTeX確實提供了一種解決方法,但可能有其他的軟件包沒有。 –