在Windows批处理文件中使用%2 *字符串变量 [英] Use %2* in string variable in Windows batch file

查看:230
本文介绍了在Windows批处理文件中使用%2 *字符串变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建批处理一个简单的脚本在Windows上运行,该脚本有3个变量:


  1. URL来打开

  2. 要打开的窗口数量

  3. 等待的时间,直到新的窗口打开

该脚本工作正常时,URL中包含类似%20%2F字符我的猜测CMD.EXE正试图用它们作为变量,我把引号之间的URL的值除,但没有帮助。

如果我使用地址:

 设置URL =htt​​p://domain.com/app.html?path=%2F%2Flocalhost%2F$c$c&do_pause=false&go=true

在浏览器中打开这样的:

  https://domain.com/app.html?path=FFlocalhostF$c$c&do_pause=false&go=true

有没有办法,我可以设置变量左右,它不跨preT这些符号作为变量名处理它的价值呢?

在此先感谢,这里是code,以供参考。这是我第一次尝试在批处理脚本程序,所以任何建议将是真正的AP preciated。

 关闭@echo回声设置变量...
设置迭代= 2
设置URL =htt​​p://domain.com/app.html?path=%2F%2Flocalhost%2F$c$c&do_pause=false&go=true
设定的时间= 5设置浏览器=C:\\ Program Files文件\\谷歌\\铬\\应用\\的chrome.exe回声运行的浏览器。
FOR / L %%我在(1,1,反复%%),DO(
%浏览器%% URL%
超时%的时间%
)ECHO浏览器正在运行,preSS输入准备时关闭此窗口。 。 。
暂停


解决方案

尝试:

 设置URL =htt​​p://domain.com/app.html?path=%%2F%%2Flocalhost%%2F$c$c&do_pause=false&go=真正

在批处理文件,你需要的地方的一%作为%%%1%2,等用于命令行PARAMS。

I'm trying to create a simple script in batch to run in Windows, the script has 3 variables:

  1. the URL to open
  2. the number of windows to open
  3. the time to wait until the new window is open

The script works fine except when the URL contains characters like %20 or %2F in which I guess cmd.exe is trying to use them as variables, I'm putting the value of the URL between quotes but that didn't help.

If I use the address:

set url="http://domain.com/app.html?path=%2F%2Flocalhost%2Fcode&do_pause=false&go=true"

the browser opens this:

https://domain.com/app.html?path=FFlocalhostFcode&do_pause=false&go=true

Is there a way I can set the variable or process its value so it does not interpret these symbols as variable names?

Thanks in advance, here is the code for reference. It is the first time I've tried to program a script in batch so any suggestion would be really appreciated.

@echo off

echo "Setting variables..."
set iterations=2
set url="http://domain.com/app.html?path=%2F%2Flocalhost%2Fcode&do_pause=false&go=true"
set time=5

set browser="C:\Program Files\Google\Chrome\Application\chrome.exe"

echo "Running the browser..."
FOR /L %%i IN (1,1,%iterations%) DO (
%browser% %url%
timeout %time%
)

ECHO Browsers are running, press Enter when ready to close this window. . .
pause

解决方案

Try:

set url="http://domain.com/app.html?path=%%2F%%2Flocalhost%%2Fcode&do_pause=false&go=true"

In batch files you need a %% in place of a % as %1, %2, etc are used for command line params.

这篇关于在Windows批处理文件中使用%2 *字符串变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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