[英]Using calculated variable in windows batch file as command line parameter
I'm trying to calculate variable value in FOR loop and then reuse it as command line parameter when calling executable file. 我正在尝试在FOR循环中计算变量值,然后在调用可执行文件时将其用作命令行参数。 I managed to calculate the variable, but i can't pass is to exe file
我设法计算了变量,但是我无法通过exe文件
Full code: 完整代码:
SetParameters.bat SetParameters.bat
SET PAYLOAD_SIZE=1024
SET OPERATIONS_COUNT=20
SET THREADS=8
SET BULKSIZE=200
And the executed bat file 和执行的蝙蝠文件
call 0_SetParameters.bat
SET MAX_EMPLOYEE_ID=0
setlocal enabledelayedexpansion
FOR %%n IN (1 2 4 8) do (
@SET /a MAX_EMPLOYEE_ID+=%OPERATIONS_COUNT%
echo !MAX_EMPLOYEE_ID!
Launcher.exe -P:%PAYLOAD_SIZE% -O:%OPERATIONS_COUNT% -N:test1 -T:%%n -BULKSIZE:%BULKSIZE% -MAX_EMPLOYEE_ID:%MAX_EMPLOYEE_ID%
)
echo !MAX_EMPLOYEE_ID! 回声!MAX_EMPLOYEE_ID! - prints calculated value that i need, but when i try to pass parameter to exe file variable is equal 0 (initial variable value).
-打印我需要的计算值,但是当我尝试将参数传递给exe文件时变量等于0(初始变量值)。
I also tried 我也试过
Launcher.exe -P:%PAYLOAD_SIZE% -O:%OPERATIONS_COUNT% -N:test1 -T:%%n -BULKSIZE:%BULKSIZE% -MAX_EMPLOYEE_ID:!MAX_EMPLOYEE_ID!
but this passes string "!MAX_EMPLOYEE_ID!" 但这会传递字符串“!MAX_EMPLOYEE_ID!” and not the numeric value.
而不是数值。 So how can i use this variable when calling exe file?
那么调用exe文件时如何使用此变量?
UPDATE: Ok, i understood what was happening here. 更新:好的,我知道这里发生了什么。 Actually everything worked, executable was called with calculated parameter, but output to console was printing -MAX_EMPLOYEE_ID:!MAX_EMPLOYEE_ID!
实际上一切正常,可执行文件是使用计算出的参数调用的,但输出到控制台的是打印-MAX_EMPLOYEE_ID:!MAX_EMPLOYEE_ID!
So correct way to call executable is 所以调用可执行文件的正确方法是
Launcher.exe -P:%PAYLOAD_SIZE% -O:%OPERATIONS_COUNT% -N:test1 -T:%%n -BULKSIZE:%BULKSIZE% -MAX_EMPLOYEE_ID:!MAX_EMPLOYEE_ID!
Here is a sample that proves your code works: it doesn't use the %%n variable as you code doesn't use it. 这是一个证明您的代码有效的示例:它不使用%% n变量,因为您的代码不使用它。
@echo off
set OPERATIONS_COUNT=5
setlocal enabledelayedexpansion
FOR %%n IN (1 2 4 8) do (
SET /a MAX_EMPLOYEE_ID+=OPERATIONS_COUNT
echo !MAX_EMPLOYEE_ID!
echo Launcher.exe -MAX_EMPLOYEE_ID:!MAX_EMPLOYEE_ID!
)
pause
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.