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
命令,则必须将百分比加倍