开发者

How to use %10 parameter in batch file when all 10 parameters need to be executed at same time?

I have created a batch file to execute 10 commands at one time as follows but everytime I run it in command prompt. It leaves the last parameter as it is i.e., it ignores the 10th parameter

echo off

c:

"H[vzmwwdminta1sd]S[#]P[8080].exe" "C:\NDM_To_BatchDispatcher\NDM\INBOUND_FILES\%1"

| "H[vzmwwdminta1sd]S[#]P[8080].exe" "C:\NDM_To_BatchDispatcher\ND开发者_JAVA技巧M\INBOUND_FILES\%2"

| "H[vzmwwdminta1sd]S[#]P[8080].exe" "C:\NDM_To_BatchDispatcher\NDM\INBOUND_FILES\%3"

| "H[vzmwwdminta1sd]S[#]P[8080].exe" "C:\NDM_To_BatchDispatcher\NDM\INBOUND_FILES\%4"

| "H[vzmwwdminta1sd]S[#]P[8080].exe" "C:\NDM_To_BatchDispatcher\NDM\INBOUND_FILES\%5"

| "H[vzmwwdminta1sd]S[#]P[8080].exe" "C:\NDM_To_BatchDispatcher\NDM\INBOUND_FILES\%6"

| "H[vzmwwdminta1sd]S[#]P[8080].exe" "C:\NDM_To_BatchDispatcher\NDM\INBOUND_FILES\%7"

| "H[vzmwwdminta1sd]S[#]P[8080].exe" "C:\NDM_To_BatchDispatcher\NDM\INBOUND_FILES\%8"

| "H[vzmwwdminta1sd]S[#]P[8080].exe" "C:\NDM_To_BatchDispatcher\NDM\INBOUND_FILES\%9"

| SHIFT

| "H[vzmwwdminta1sd]S[#]P[8080].exe" "C:\NDM_To_BatchDispatcher\NDM\INBOUND_FILES\%9"

Any suggestions??

Thanks Priyanka


You can try doing this in a for loop:

for /l %%i in (1,1,10) do (
    "H[vzmwwdminta1sd]S[#]P[8080].exe" "C:\NDM_To_BatchDispatcher\NDM\INBOUND_FILES\%1"
    SHIFT
)

EDIT: shift doesn't work in a for loop because all the lines within the parens are interpreted at the same time, for all iterations, but you can roll your own loop:

@echo off
set i=1
:loop
if %i% GEQ 11 goto :end
"H[vzmwwdminta1sd]S[#]P[8080].exe" "C:\NDM_To_BatchDispatcher\NDM\INBOUND_FILES\%1"
SHIFT
set /a i+=1
goto :loop

:end
@echo All done.

Another solution would be to use a for loop but call a sub-procedure to do the shift.


You must note that the pipeline character in PROC1 | PROC2 is NOT intended for parallel (simultaneous) execution of PROC1 and PROC2, but to connect the output of PROC1 to the input of PROC2. If this is what you want, the following method allows you to execute this way any number of commands:

@echo off
"H[vzmwwdminta1sd]S[#]P[8080].exe" "C:\NDM_To_BatchDispatcher\NDM\INBOUND_FILES\%1" > output.txt
:loop
shift
if "%1" == "" goto end
ren output.txt input.txt
"H[vzmwwdminta1sd]S[#]P[8080].exe" "C:\NDM_To_BatchDispatcher\NDM\INBOUND_FILES\%1" < input.txt > output.txt
goto loop
:end
type output.txt
del output.txt

If you want to execute all the commands in parallel, then you must use START as suggested above:

@echo off
:loop
start "Command %1" "H[vzmwwdminta1sd]S[#]P[8080].exe" "C:\NDM_To_BatchDispatcher\NDM\INBOUND_FILES\%1" 
shift
if not "%1" == "" goto loop


You could start the multiple instances simultaneously also with start.exe.

@echo off
set i=1
:loop
if %i% GEQ 11 goto :end
start "Titel%i%" "H[vzmwwdminta1sd]S[#]P[8080].exe" "C:\NDM_To_BatchDispatcher\NDM\INBOUND_FILES\%1"
SHIFT
set /a i+=1
goto :loop
:end

Or you save the variables first into p1, p2, ..., p10

@echo off
set prog="H[vzmwwdminta1sd]S[#]P[8080].exe"
set "param=C:\NDM_To_BatchDispatcher\NDM\INBOUND_FILES\"
set i=1
:loop
if %i% GEQ 11 goto :end
set "p%i%=%1"
SHIFT
set /a i+=1
goto :loop
:end

%prog% "%param%p1%" ^
 | %prog% "%param%p2%" ^
 | %prog% "%param%p3%" ^
 | %prog% "%param%p4%" ^
 | %prog% "%param%p5%" ^
 | %prog% "%param%p6%" ^
 | %prog% "%param%p7%" ^
 | %prog% "%param%p8%" ^
 | %prog% "%param%p9%" ^
 | %prog% "%param%p10%"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜