如何在批处理文件中转义&符号(或从Windows命令行转义),以便使用start
命令打开网址中带有&号的网页?
双引号不适用于start
;这将启动一个新的命令行窗口。
更新1:Wael Dalloul的解决方案有效。此外,如果URL中有URL编码的字符(例如,空格编码为%20),并且它在批处理文件中,则必须将'%‘编码为'%%’。示例中的情况并非如此。
例如,在命令行(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。
发布于 2015-01-15 17:59:31
来自命令的
&
是这样转义的:^&
(基于@Wael Dalloul的answer)%
不需要转义举个例子:
start http://www.google.com/search?client=opera^&rls=en^&q=escape+ampersand%20and%20percentage+in+cmd^&sourceid=opera^&ie=utf-8^&oe=utf-8
批处理文件中的
&
是这样转义的:^&
(基于@Wael Dalloul的answer)%
是这样转义的:%%
(基于操作更新)举个例子:
start http://www.google.com/search?client=opera^&rls=en^&q=escape+ampersand%%20and%%20percentage+in+batch+file^&sourceid=opera^&ie=utf-8^&oe=utf-8
发布于 2009-08-25 10:49:13
&
用于分隔命令。因此,您可以使用^
来转义&
。
发布于 2009-08-25 10:41:07
如果你提供了一个伪的第一个参数,你可以用引号把它括起来。
请注意,在这种情况下,您需要提供一个虚拟的第一个参数,因为如果第一个参数被引用,start
会将其视为新控制台窗口的标题。因此,下面的代码应该可以工作(在这里也是这样):
start "" "http://www.google.com/search?client=opera&rls=en&q=escape+ampersand&sourceid=opera&ie=utf-8&oe=utf-8"
https://stackoverflow.com/questions/1327431
复制相似问题