Batch file with variable command line parameter

I have the following batch file:

:LOOP
ping %1
ping %2
goto LOOP

This file only works with two command line options. How to make this work with a variable number of command line options. For example, if four command-line options were provided at run time, then it should ping on all four servers.

Any help appreciated

+3
source share
2 answers

, , shift. . , , , .

%*, :

@echo off
:loop
for %%x in (%*) do ping %%x
goto :loop

SVN-.

+4

EDIT: Johannes, , script:

:

:loop 
if %1x==x goto :EOF
ping %1
shift
goto :LOOP

:

:loop2
call :loop %*
goto :loop2

:loop 
if %1x==x goto :EOF
ping %1
shift
goto :LOOP
0

Source: https://habr.com/ru/post/1754689/


All Articles