windows - 如何转义批处理文件中的符号?

标签 windows batch-file cmd escaping ampersand

如何在批处理文件(或从 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。

最佳答案

& 用于分隔命令。因此,您可以使用 ^ 来转义 &

关于windows - 如何转义批处理文件中的符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1327431/

相关文章:

linux - 相互比较两个文本文件

windows - 如何验证批处理文件中的文件是否存在?

windows - 使用 7ZIP 和 CMD 压缩和删除超过 7 天的文件

scripting - 在批处理脚本中转义双引号

windows - 用于从文本中删除特殊字符的应用程序或批处理文件脚本

python - 通过cmd启动识别正在运行的python程序

powershell - 从 MSBuild Exec 任务运行 powershell 脚本时出现异常

c# - 如何在网络共享文件夹的媒体元素中播放视频

c++ - 开源网络摄像头库

windows - 文件夹路径中的批处理通配符 (*) 到随时间变化的目标文件夹名称