James
James

Reputation: 31

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

Upvotes: 3

Views: 39942

Answers (2)

Joey
Joey

Reputation: 354456

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.

Upvotes: 6

Greg Hewgill
Greg Hewgill

Reputation: 992947

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.

Upvotes: 4

Related Questions