3

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

start notepad loop

James
  • 31
  • 1
  • 1
  • 2
  • Why would you want to?v (perhaps see here: http://ss64.com/nt/for.html) – soandos May 11 '11 at 19:52
  • 1
    Possible duplicate of [How to create an infinite loop in Windows batch file?](http://stackoverflow.com/questions/5487473/how-to-create-an-infinite-loop-in-windows-batch-file) – user Sep 19 '16 at 21:44

2 Answers2

6

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.

Joey
  • 344,408
  • 85
  • 689
  • 683
  • Thanks for this. It works perfectly. Could you explain the syntax to make the answer even better ? – ereOn Aug 20 '15 at 17:41
4

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.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285