user1880147
user1880147

Reputation: 13

calling one batch file mutiple times

I want to call a batch file from another batch file ten times. I want to know is there anyway i can use looping in batch commands, something like while or for.

For now i was working on this

set _script_name=script1
echo %_script_name% 
set num1=0
set num2=1 
set terminator=5

SET _log_path=D:\USERS\Administrator\Desktop\batch_v2\Logs\
SET device1=4df1a5c715b65fb1
SET _monkey_path=D:\USERS\Administrator\Desktop\adt-bundle-windows-x86_64-20130729\sdk\tools\

cd %_monkey_path%
:loop
set /a num1= %num1% + %num2%
if %num1%==%terminator% goto close
goto open
:close
echo %num1%
pause 
exit
:open

monkeyrunner.bat D:\USERS\Administrator\Desktop\batch_v2\script.py %device1% > %_log_path%newlog.txt
goto loop

I want to call script.py in a loop.

or is there any way i can use loop in my py file to call my batch file within while in the py file.

Basically my objectove is to use a batch file to pull logs after each iteration of my py script.

Using this script is called only once

Upvotes: 0

Views: 63

Answers (1)

MichaelS
MichaelS

Reputation: 6042

Yes, there is a FOR construct in batch:

FOR /L %%G IN (1,1,100) DO (
    START C:\path\to\your.bat
)

This code will run your bat file 100 times.

The syntax is FOR /L %%parameter IN (start,step,end) DO command

For more information check http://ss64.com/nt/for_l.html

If you want to run all your bats in parallel each in it's own console use START your.bat. If you want them to run in background use START /B your.bat. If you want them to run one after another and each in it's own console use START /WAIT your.bat. The last option is to run them one after another AND all in your main console use CALL your.bat.

Upvotes: 1

Related Questions