Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to loop a command continually in batch files

As the title says what parameters would you use in a batch file to continually execute a command e.g.

start notepad loop

like image 889
James Avatar asked Mar 02 '26 05:03

James


2 Answers

Another option in a single line (which will also work from the command line):

for /l %x in (1,0,2) do (start /wait notepad)

If you're using that in a batch file, use

for /l %%x in (1,0,2) do (start /wait notepad)

instead.

like image 126
Joey Avatar answered Mar 05 '26 11:03

Joey


Use goto:

:loop
start /wait notepad
goto loop

Note that I have used start /wait here. If you don't do that, your batch file won't wait for notepad to exit, and you'll start a zillion notepads and probably eventually crash.

like image 37
Greg Hewgill Avatar answered Mar 05 '26 10:03

Greg Hewgill