No announcement yet.

For %%Y in () do CMD .....

  • Filter
  • Time
  • Show
Clear All
new posts

  • For %%Y in () do CMD .....


    I'm trying to get this batch file to cycle through the "Y's" without running the entire Y set at the same time. I know I can remove the START but then it will go one by one and it'll be too slow.

    The Y's are IP segments. If I leave the START, it runs 254 DOS windows times 15 segments. That's 2,310 windows and my system freezes up.

    I can change Y to hold only 3 or 4 segments at a time but then the batch file will be longer.

    I added the waitfor and the taskkill to kill the xcopy processes after it's done and it works great when I run it on smaller Y's subsets.

    Any ideas how to run a segment (154 DOS windows) at a time and move to the next segment?

    for %%Y in (7,23,26,29,30,34,35,36,38,39,41,42,43,44,45 ) do CMD /C for /L %%X in (100,1,254) do START xcopy c:\exception.sites \\192.168.%%Y.%%X\admin$\sun\java\Deployment /Y

    Waitfor /T 8 NonExistingEvent
    taskkill /IM xcopy.exe* /F /T
    Waitfor /T 8 NonExistingEvent
    Last edited by haleman; 17th January 2014, 22:19.

  • #2
    Re: For %%Y in () do CMD .....

    You can add a little subroutine to the scipt. The subroutine will be called (call:limit 100) right after each new xcopy task was launced. The subroutine counts the amound of specific xcopy processes that already are running. If the number exceeds a set value (100), then the script will wait with launching new copy tasks untill that the amount of processen is below the value.

    @goto :begin of batch
      + + + sub routines + + +
    add sub routines her
    :begin of batch
    @echo off
    for %%Y in (7,23,26,29,30,34,35,36,38,39,41,42,43,44,45 ) do for /L %%X in (100,1,254) do (START "CopyTo"/MIN  xcopy "c:\exception.sites" "\\192.168.%%Y.%%X\admin$\sun\java\Deployment\" /Y  & call:limit 100)

    And this is the subroutine that should be added to the script above:
    :limit -----------------------------------------------------------------
    for /f "tokens=*" %%! in (
       'tasklist.exe /NH /FI "WINDOWTITLE eq CopyTo" ^| find /I /c "xcopy.exe"'
        ) do IF %%!0 GEQ %*0 (
          cls & echo.tasks are running! & echo.
          <nul (Set /P j=%%! simultaneous tasks are running, waiting...)
          timeout /t 3 /NoBreak >nul
          goto:limit) else (cls & echo.tasks are running!)
    If not defined n (Set /a n= 2) else set /a n+=1
    exit /b 0 --------------------------------------------------------------

    There is also a second soubroutine. The reason fot that is I personally don't like seing the first "100" (the value from the sample) fired all in one bang. Therefore I incorporated the second subroutine which also is invoked after each xcopy task that is launched. Now instead of "bang" you'll see pop pop pop the windows rapidly appearing one by one.
    Because with available default dos commands you cannot create pauses shorter than one second, I created the very! short delay with a kinda progressmonitor visible in the title bar:

    :titlebar --------------------------------------------------------------
    set "title=do not close this window"
    Set _title=(Set "_mill=\ ")
    IF DEFINED _mill (call:updtitle) ELSE (%_title%)
    title %title%           %n% tasks were started so far    %_mill%   & exit /b
     If "%_mill:~-2%"=="\ " (Set "_mill=^|" & goto:eof)
     If "%_mill:~-2%"=="^|" (Set "_mill=/ " & goto:eof)
     If "%_mill:~-2%"=="/ " (Set "_mill=--" & goto:eof)
     %_title% & exit /b ----------------------------------------------------
    Copy both subroutines and paste them in the sample script over the blue line add sub routines her

    Last edited by Rems; 21st January 2014, 00:01.

    This posting is provided "AS IS" with no warranties, and confers no rights.


    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts


    • #3
      Re: For %%Y in () do CMD .....


      you rock brother! Thank you!