Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::: ** Batch Multithreading example by T3RRY ** :::
- @Echo Off & CD "%~dp0" :::
- :::::::::::::::::::::::::::::::::::::::::::::::::::
- ::: - Test if Thread Two is to be executed
- If /I "%~1" == "Thread2" Goto :Thread2
- ::: - Thread One Actions
- Mode 160,40
- CHCP 65001 & CLS
- ::: { Creates variable Æ = Ascii-27 escape code.
- ::: - http://www.dostips.com/forum/viewtopic.php?t=1733
- ::: - https://stackoverflow.com/a/34923514/12343998
- :::
- ::: - Æ (Alt 146) can be used with and without DelayedExpansion.
- Setlocal
- For /F "tokens=2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
- Endlocal
- Set "Æ=%%a"
- )
- ::: }
- ::: - Localise Thread Ones Environment
- Setlocal EnableDelayedExpansion
- If not "!Priority!"=="" (
- Set Priority=High
- Start /B /High "" "%~F0"
- )
- ::: - Ensure previous Signal files removed in case program exited incorrectly
- Del /Q /F "%TEMP%\CMDrun.log" > Nul 2> Nul
- Del /Q /F "%TEMP%\CMDend.log" > Nul 2> Nul
- CLS
- Set "Chars=•☺☻◘○"
- :Loop
- ::: - Launch Thread Two in Same window if Not already Running
- ::: - ** Conditional tests on signal files redirect errors to Standard error to prevent erroneous output **
- ::: - when testing occurs at the same time the file is being written to.
- (IF Not Exist "%TEMP%\CMDrun.log" Start /B "" "%~F0" Thread2) 2>Nul
- ::: - Animation To indicate commands in thread one are running. This example demonstrates different For loops being
- ::: - Executed simultaneously
- For /L %%T in (0,1,4) Do (
- Set L1#=0
- For /L %%Y in (2,2,38) Do (
- Set /A L1#+=1
- Set L1[!L1#!]=Echo/
- For /L %%X In (2,2,160) Do (
- For %%i in (!L1#!) Do Set "L1[!L1#!]=!L1[%%i]!%Æ%[%%Y;%%XH%Æ%!!%%X;%%Y0m!Chars:~%%T,1!"
- )
- For %%E in (!L1#!) Do !L1[%%E]!
- Title THREAD ONE
- )
- rem For /L %%E in (1,1,!L1#!) Do !L1[%%E]!
- )
- ::: - Exit Thread One once Thread Two has Completed
- (IF Exist "%TEMP%\CMDend.log" Goto :End_Loop) 2>Nul
- Goto :Loop
- :End_Loop
- ::: - Clean up Signal Files
- Echo.
- Del /Q /F "%TEMP%\CMDrun.log"
- Del /Q /F "%TEMP%\CMDend.log"
- Title Example Complete
- Pause >Nul
- ::: - Demonstrate stability of multithreading through repetition
- Start "" "%~F0"
- Exit
- :Thread2
- TITLE Coloring the faces
- ::: Localise Thread Two's Environment
- CHCP 65001 > Nul
- ::: { Creates variable Æ = Ascii-27 escape code.
- ::: - http://www.dostips.com/forum/viewtopic.php?t=1733
- ::: - https://stackoverflow.com/a/34923514/12343998
- :::
- ::: - Æ (Alt 146) can be used with and without DelayedExpansion.
- Setlocal
- For /F "tokens=2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
- Endlocal
- Set "Æ=%%a"
- )
- ::: }
- Set "CharSet=/-\-"
- Setlocal EnableDelayedExpansion
- >"%TEMP%\CMDrun.log" (Echo running)
- For /l %%n in (1,1,25) Do (
- For /L %%z in (0,1,3) Do (
- Set L2#=0
- For /L %%a in (39,-2,1) Do (
- Set /A L2#+=1
- Set L2[!L2#!]=Echo/
- For /L %%b In (159,-2,1) Do (
- For %%i in (!L2#!) Do Set "L2[!L2#!]=!L2[%%i]!%Æ%[%%a;%%bH%Æ%!!%%!!%%!!!!!%%z,1!"
- )
- For %%v in (!L2#!) Do !L2[%%v]!
- TITLE THREAD TWO
- )
- rem For /L %%c in (1,1,!L2#!) Do !L2[%%c]!
- )
- )
- >"%TEMP%\CMDend.log" (Echo finished)
- ::: - Hard exit of Thread Two used to prevent script overflow.
- EXIT
Add Comment
Please, Sign In to add comment