SoFunction
Updated on 2025-04-09

bat Pass parameter call problem solving record

bat pass parameters

When calling bat, there is a small problem with passing parameters, please record it.

1. Problem description:

When passing the parameter, the received value is incorrect. "1,2,3" is passed, and when receiving, only 1 is left. There is nothing behind.

solve:

The reason is that the syntax is wrong when bat is taken.

Syntax 1:

%0 represents bat file name

%1 represents the first parameter

%2 represents the second parameter

%2 represents the second parameter

example 1:

> type args_handle.bat
@echo arg1 : %1                
@echo arg2 : %2                
> args_handle.bat "aaa=bbb,ccc" "ddd;eee"
arg1 : "aaa=bbb,ccc"
arg2 : "ddd;eee"

Syntax 2:

%~1 The first parameter, remove double quotes

%~2 The second parameter, remove double quotes

example 2:

> type args_handle.bat
@echo arg1 : %~1
@echo arg2 : %~2
> args_handle.bat "aaa=bbb,ccc" "ddd=eee"
arg1 : aaa=bbb,ccc
arg2 : ddd=eee

Syntax 3:

%* represents all parameters

2. Problem description:

When debugging the program yesterday, there was another new bug. In the database SQL Server, trigger passes 200 parameters to bat. When triggering, it sends 200 parameters (parameter format 1, 2, 3, 4, 5, 6...), but when receiving the bat method, it sends log confirmation, but only receives the 87th characoter, and all the following are cut, and I don’t know the reason.

solve:

Method investigation →Solution is completed

Follow-up:

Scene description:

In trigger, 200 parameters are passed as a string to bat.

Cause of the problem: The declaration of the string is incorrect. The variable passed as a parameter is written as sysname, not declared with varchar. systemname is a built-in data type in SqlServer, with a length of 128 characters.

References:/?

The above is the detailed content of the problem solving record of bat passing parameters. For more information about bat passing parameters, please pay attention to my other related articles!