【发布时间】:2010-11-22 13:58:26
【问题描述】:
如何在批处理文件(或从
Windows 命令行),以便使用start 命令
打开 URL 中带有 & 符号的网页?
双引号不适用于start;这开始了一个新的
而是命令行窗口。
更新 1:Wael Dalloul 的解决方案有效。此外,如果 有 URL 编码的字符(例如,空格被编码为 %20) 在 URL 中并且 它在一个批处理文件中 那么 '%' 必须是 编码为“%%”。示例中并非如此。
例如,来自命令行 (CMD.EXE):
start http://www.google.com/search?client=opera&rls=en&q=escape+ampersand&sourceid=opera&ie=utf-8&oe=utf-8
将导致
http://www.google.com/search?client=opera
在默认浏览器中打开并且在命令行窗口中出现这些错误:
'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.
平台:Windows XP 64 位 SP2。
【问题讨论】:
-
我已经编辑了 belugabob 的答案,所以它现在应该可以工作了。这只是
start中的一个怪癖,如果不加思索地应用,它会导致引用参数失败。总的来说,我认为将参数括在引号中比在其中转义每个需要转义的字符更容易且更不容易出错。 -
加号
+前面应该加什么来逃避呢? -
在 PowerShell 中
start "http://www.google.com/search?client=opera&rls=en&q=escape+ampersand&sourceid=opera&ie=utf-8&oe=utf-8"有效,因为 PowerShell will strip quotes out
标签: windows batch-file cmd escaping ampersand