batch-file - 变量表达式 %Var% 在批处理文件中的 for 循环中不起作用
问题描述
FOR /F "tokens=* USEBACKQ" %F IN (java -jar %MAVEN_HOME%\jenkins-cli.jar -s http://someip.com build /dev/ -s --username **** --password ***) DO (SET var=%F)
这里%MAVEN_HOME%
的值没有被实际值替换,但是当我在没有for
循环的情况下运行它时,它工作正常。
有人可以解决这个问题并MAVEN_HOME
用实际值替换吗?
解决方案
您需要` `
像这样输入命令
FOR /F "tokens=* USEBACKQ" %F IN (`java -jar %MAVEN_HOME%\jenkins-cli.jar -s http://someip.com build /dev/ -s --username **** --password ***`) DO (SET var=%F)
因为语法是
C:\>for /?
Runs a specified command for each file in a set of files.
FOR %variable IN (set) DO command [command-parameters]
%variable Specifies a single letter replaceable parameter.
(set) Specifies a set of one or more files. Wildcards may be used.
command Specifies the command to carry out for each file.
command-parameters
Specifies parameters or switches for the specified command.
To use the FOR command in a batch program, specify %%variable instead
of %variable. Variable names are case sensitive, so %i is different
from %I.
...
FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]
or, if usebackq option present:
FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ('string') DO command [command-parameters]
FOR /F ["options"] %variable IN (`command`) DO command [command-parameters]
如您所见,USEBACKQ
命令必须用反引号括起来,并且还说如果要for
在批处理文件中使用该命令,则必须将百分比加倍
推荐阅读
- flutter - Flutter:如何防止我的主要小部件旋转并仍然跟踪它的方向?
- node.js - 不正确的用户/通过拒绝从节点/express/mongodb 需要很长时间
- r - 是否可以沿 facet_grid() 使用 geom_table()?
- java - JDK SE 8 的内存分配问题(来自 AdoptOpenJDK 的 OpenJDK 8 不会发生)
- c++ - 可以使用 SPACE 代替 ENTER 来接受 C++ 中的输入吗?
- pentaho - 为什么你认为 pentaho 仪表板选择过滤器会在浏览器重新加载时得到修复?
- c# - 如何制作 2D Unity Sprite Jump?
- excel - 字体格式和或条件
- java - 为什么即使我等待站点完成加载,我也无法获取数据?
- matlab - 我在 matlab 中编写了以下代码来随机化,然后在 3x4 矩阵中将数字 3 到 8 舍入,但我不想在行中重复数字