Reputation: 3
I'm working on a project and I need to create multiple batch files from a text file. Meaning that, I want to run a script that will loop into a test.txt that contains multiple IPs. I want create a batch file for every IP in that list. The end result will be that I will use START to loop through newly created batch files so I can have multiple instances that run at the same time.
Thanks.
Upvotes: 0
Views: 649
Reputation: 130809
I'm assuming you want each script to do the same thing, only with a different IP address each time. Creating a separate batch script for each IP address is totally unnecessary - you simply need one script that takes the IP address as a parameter. Assuming the IP address is the first parameter, then it would be referenced using %1
. Here is a trivial demo - obviously you would modify processIP.bat to do what you want with the IP address.
main.bat
@echo off
for /f %%A in (test.txt) do start "" processIP %%A
processIP.bat
@echo off
echo Processing %1 to demonstrate how to access the IP parameter
pause
You could even combine everything into one script. %~f0
expands to the full path of the currently running batch script, so the script knows how to call itself, no matter where it is located or what name it has. You simply pass an extra parameter with a specific value to indicate which code to execute.
anyname.bat
@echo off
if %1==:processIP (
shift /1
goto :processIP
)
for /f %%A in (test.txt) do start "" "%~f0" :processIP %%A
exit /b
:processIP
echo Processing %1 to demonstrate how to access the IP parameter
pause
Certainly you can have a batch script dynamically create and call a new batch script on the fly, but usually there is a better way to accomplish the task at hand.
Upvotes: 1