如何在批處理文件中轉義&符號? - How do I escape ampersands in batch files?

問題:

How do I escape ampersands in a batch file (or from the Windows command line) in order to use the start command to open web pages with ampersands in the URL?如何在批處理文件(或從 Windows 命令行)中轉義與號,以便使用start命令打開 URL 中帶有與號的網頁?

Double quotes will not work with start ;雙引號不適用於start this starts a new command-line window instead.這將啓動一個新的命令行窗口。

Update 1 : Wael Dalloul's solution works.更新 1 :Wael Dalloul 的解決方案有效。 In addition, if there are URL encoded characters (eg space is encoded as %20) in the URL and it is in a batch file then '%' must be encoded as '%%'.此外,如果 URL 中有 URL 編碼字符(例如空格編碼爲 %20)並且它在批處理文件中,則 '%' 必須編碼爲 '%%'。 This is not the case in the example.示例中並非如此。

Example, from the command line ( CMD.EXE ):例如,從命令行( CMD.EXE ):

start http://www.google.com/search?client=opera&rls=en&q=escape+ampersand&sourceid=opera&ie=utf-8&oe=utf-8

will result in會導致

http://www.google.com/search?client=opera 

being opened in the default browser and these errors in the command line window:在默認瀏覽器中打開並在命令行窗口中出現這些錯誤:

'rls' is not recognized as an internal or external command,
operable program or batch file.
'q' is not recognized as an internal or external command,
operable program or batch file.
'sourceid' is not recognized as an internal or external command,
operable program or batch file.
'ie' is not recognized as an internal or external command,
operable program or batch file.
'oe' is not recognized as an internal or external command,
operable program or batch file.

Platform: Windows XP 64 bit SP2.平臺:Windows XP 64 位 SP2。


解決方案:

參考一: https://en.stackoom.com/question/5ZKB
參考二: https://stackoom.com/question/5ZKB
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章