This answer addresses the main question that is listed in the header of your message, not the code you provided.
To start the for loop in a separate window ( cmd ), the start command is required. In addition, an explicit instance of cmd must be specified in order to avoid problems with start when calling internal commands (for example, brackets can cause errors), and also have control over what happens with the new window after the cycle is completed.
The following command line executes the for loop in a new cmd window, which remains open after the loop ends (very useful for debugging):
start "" /WAIT cmd /K "for /L %%X in (0,1,2) do echo %%X"
Type exit in a new window to close it. To automatically close a new window, replace /K with /C
If you do not want your main (calling) script package to wait for the loop to complete and close a new window, remove the /WAIT switch. This launches the command line, but the main script immediately continues execution. This allows you to run multiple for loops in separate windows at the same time.
This method is not limited to just calling for loops.
source share