如何在批处理文件中删除&符号? [英] How do I escape ampersands in batch files?

查看:310
本文介绍了如何在批处理文件中删除&符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在批处理文件(或从
Windows命令行中)中删除&符号,以便使用 start 命令
打开网址中含有&符号的网页?

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?

双引号不适用于 start ;这将启动一个新的
命令行窗口。

Double quotes will not work with start; this starts a new command-line window instead.

更新1 :Wael Dalloul的解决方案适用。另外,如果
在URL中有URL编码的字符(例如,空格被编码为
%20),那么它在批处理文件中,那么'%'必须是
编码为%%。例如,从命令行( CMD.EXE ):

Update 1: Wael Dalloul's solution works. In addition, if there are URL encoded characters (e.g. space is encoded as %20) in the URL and it is in a batch file then '%' must be encoded as '%%'. This is not the case in the example.

/ p>

Example, from the command line (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 

在默认浏览器中打开,并在命令行窗口中显示这些错误:

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.

平台:Windows XP 64位SP2。

Platform: Windows XP 64 bit SP2.

推荐答案

从cmd


  • & 转义为: ^& (基于@Wael Dalloul的答案

  • 不需要转义

  • & is escaped like this: ^& (based on @Wael Dalloul's answer)
  • % does not need to be escaped

一个例子:

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的答案

  • 转义为: %% (基于OPs更新)

  • & is escaped like this: ^& (based on @Wael Dalloul's answer)
  • % is escaped like this: %% (based on the OPs update)

一个例子:

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

这篇关于如何在批处理文件中删除&符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆